Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public abstract class JacksonMetric extends JacksonEvent implements Metric {
protected static final String SCHEMA_URL_KEY = "schemaUrl";
protected static final String EXEMPLARS_KEY = "exemplars";
protected static final String FLAGS_KEY = "flags";
protected static final String METADATA_KEY = "metadata";
private boolean flattenAttributes;

protected JacksonMetric(Builder builder, boolean flattenAttributes) {
Expand Down Expand Up @@ -101,6 +102,11 @@ public String getKind() {
return this.get(KIND_KEY, String.class);
}

@Override
public Map<String, Object> getMetricMetadata() {
return this.get(METADATA_KEY, Map.class);
}

@Override
public String getStartTime() {
return this.get(START_TIME_KEY, String.class);
Expand Down Expand Up @@ -256,7 +262,7 @@ public T withServiceName(final String serviceName) {
}

/**
* Sets the scope of the log event
* Sets the scope of the metric event
*
* @param scope scope to be set
* @return the builder
Expand All @@ -268,7 +274,19 @@ public T withScope(final Map<String, Object> scope) {
}

/**
* Sets the resource of the log event
* Sets the metadata of the metric event
*
* @param metadata metadata to be set
* @return the builder
* @since 2.11
*/
public T withMetricMetadata(final Map<String, Object> metadata) {
put(METADATA_KEY, metadata);
return getThis();
}

/**
* Sets the resource of the metric event
*
* @param resource resource to be set
* @return the builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,23 @@ enum KIND {GAUGE, HISTOGRAM, EXPONENTIAL_HISTOGRAM, SUM, SUMMARY}
Integer getFlags();

/**
* Gets the scope of this log event.
* Gets the scope of this metric event.
*
* @return the scope
* @since 2.11
*/
Map<String, Object> getScope();

/**
* Gets the resource of this log event.
* Gets the metadata of this metric event.
*
* @return the metadata
* @since 2.11
*/
Map<String, Object> getMetricMetadata();

/**
* Gets the resource of this metric event.
*
* @return the resource
* @since 2.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class JacksonSpan extends JacksonEvent implements Span {
protected static final String ATTRIBUTES_KEY = "attributes";
private static final String DROPPED_ATTRIBUTES_COUNT_KEY = "droppedAttributesCount";
private static final String EVENTS_KEY = "events";
private static final String SCHEMA_URL_KEY = "schemaUrl";
private static final String DROPPED_EVENTS_COUNT_KEY = "droppedEventsCount";
private static final String LINKS_KEY = "links";
private static final String DROPPED_LINKS_COUNT_KEY = "droppedLinksCount";
Expand Down Expand Up @@ -91,6 +92,11 @@ protected void checkAndSetDefaultValues() {
putIfAbsent(DROPPED_EVENTS_COUNT_KEY, Integer.class, 0);
}

@Override
public String getSchemaUrl() {
return this.get(SCHEMA_URL_KEY, String.class);
}

@Override
public String getTraceId() {
return this.get(TRACE_ID_KEY, String.class);
Expand Down Expand Up @@ -406,7 +412,19 @@ public Builder withFlags(final Integer flags) {
}

/**
* Sets the status of the log event
* Sets the schema url of span
*
* @param schemaUrl schema url
* @return returns the builder
* @since 2.11
*/
public Builder withSchemaUrl(final String schemaUrl) {
data.put(SCHEMA_URL_KEY, schemaUrl);
return this;
}

/**
* Sets the status of the span event
*
* @param status status to be set
* @return the builder
Expand All @@ -418,7 +436,7 @@ public Builder withStatus(final Map<String, Object> status) {
}

/**
* Sets the scope of the log event
* Sets the scope of the span event
*
* @param scope scope to be set
* @return the builder
Expand All @@ -430,7 +448,7 @@ public Builder withScope(final Map<String, Object> scope) {
}

/**
* Sets the resource of the log event
* Sets the resource of the span event
*
* @param resource resource to be set
* @return the builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,31 @@ public interface Span extends Event {
void setServiceName(final String serviceName);

/**
* Gets the scope of this log event.
* Gets the schema url of this span event.
*
* @return the schema url
* @since 2.11
*/
String getSchemaUrl();

/**
* Gets the scope of this span event.
*
* @return the scope
* @since 2.11
*/
Map<String, Object> getScope();

/**
* Gets the resource of this log event.
* Gets the resource of this span event.
*
* @return the resource
* @since 2.11
*/
Map<String, Object> getResource();

/**
* Gets the status of this log event.
* Gets the status of this span event.
*
* @return the status
* @since 2.11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class JacksonGaugeTest {
"key2", TEST_KEY2);
protected static final Map<String, Object> TEST_SCOPE = ImmutableMap.of("name", UUID.randomUUID().toString(), "version", UUID.randomUUID().toString(), "attributes", List.of(Map.of("key", UUID.randomUUID().toString(), "value", UUID.randomUUID().toString())));
protected static final Map<String, Object> TEST_RESOURCE = ImmutableMap.of("attributes", List.of(Map.of("key", UUID.randomUUID().toString(), "value", UUID.randomUUID().toString())));
protected static final Map<String, Object> TEST_METADATA = ImmutableMap.of("metadataKey1", UUID.randomUUID().toString(), "metadataKey2", UUID.randomUUID().toString(), "metadataKey3", UUID.randomUUID().toString());
protected static final String TEST_SERVICE_NAME = "service";
protected static final String TEST_NAME = "name";
protected static final String TEST_DESCRIPTION = "description";
Expand Down Expand Up @@ -72,6 +73,7 @@ public void setup() {
.withUnit(TEST_UNIT_NAME)
.withScope(TEST_SCOPE)
.withResource(TEST_RESOURCE)
.withMetricMetadata(TEST_METADATA)
.withValue(TEST_VALUE)
.withServiceName(TEST_SERVICE_NAME)
.withExemplars(TEST_EXEMPLARS)
Expand Down Expand Up @@ -160,6 +162,12 @@ public void testGetResource() {
assertThat(resource, is(equalTo(TEST_RESOURCE)));
}

@Test
public void testGetMetricMetadata() {
final Map<String, Object> metadata = gauge.getMetricMetadata();
assertThat(metadata, is(equalTo(TEST_METADATA)));
}

@Test
public void testGetTime() {
final String endTime = gauge.getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class JacksonSpanTest {
protected static final String TEST_PARENT_SPAN_ID = UUID.randomUUID().toString();
protected static final String TEST_NAME = UUID.randomUUID().toString();
protected static final String TEST_KIND = UUID.randomUUID().toString();
protected static final String TEST_SCHEMA_URL = UUID.randomUUID().toString();
protected static final int TEST_FLAGS = 10;
protected static final String TEST_START_TIME = UUID.randomUUID().toString();
protected static final String TEST_END_TIME = UUID.randomUUID().toString();
Expand Down Expand Up @@ -106,6 +107,7 @@ public void setup() {
.withResource(TEST_RESOURCE)
.withStatus(TEST_STATUS)
.withStartTime(TEST_START_TIME)
.withSchemaUrl(TEST_SCHEMA_URL)
.withEndTime(TEST_END_TIME)
.withAttributes(TEST_ATTRIBUTES)
.withDroppedAttributesCount(TEST_DROPPED_ATTRIBUTES_COUNT)
Expand Down Expand Up @@ -168,6 +170,12 @@ public void testGetFlags() {
assertThat(flags, is(equalTo(TEST_FLAGS)));
}

@Test
public void testGetSchemaUrl() {
final String schemaUrl = jacksonSpan.getSchemaUrl();
assertThat(schemaUrl, is(equalTo(TEST_SCHEMA_URL)));
}

@Test
public void testGetStartTime() {
final String GetStartTime = jacksonSpan.getStartTime();
Expand Down
Loading
Loading