Skip to content

Commit

Permalink
More support
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Apr 16, 2021
1 parent b8bdbb5 commit 0aac0ec
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,22 @@ private static void setExtraAttributes(Telemetry telemetry, Attributes attribute
telemetry.getContext().getUser().setUserAgent((String) value);
return;
}
if (stringKey.equals("ai.preview.instrumentation_key") && value instanceof String) {
telemetry.getContext().setInstrumentationKey((String) value);
return;
}
if (stringKey.equals("ai.preview.service_name") && value instanceof String) {
telemetry.getContext().getCloud().setRole((String) value);
return;
}
if (stringKey.equals("ai.preview.service_instance_id") && value instanceof String) {
telemetry.getContext().getCloud().setRoleInstance((String) value);
return;
}
if (stringKey.equals("ai.preview.service_version") && value instanceof String) {
telemetry.getContext().getComponent().setVersion((String) value);
return;
}
int index = stringKey.indexOf(".");
String prefix = index == -1 ? stringKey : stringKey.substring(0, index);
if (STANDARD_ATTRIBUTE_PREFIXES.contains(prefix)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint=http://host.docker.internal:6060/",
"role": {
"name": "testrolename",
"instance": "testroleinstance"
},
"preview": {
"httpMethodInOperationName": true,
"openTelemetryApiSupport": true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public String testApi() {
return "OK!";
}

@GetMapping("/test-overriding-ikey-etc")
public String testOverridingIkeyEtc() {
Span.current().setAttribute("ai.preview.instrumentation_key", "12341234-1234-1234-1234-123412341234");
Span.current().setAttribute("ai.preview.service_name", "role-name-here");
Span.current().setAttribute("ai.preview.service_instance_id", "role-instance-here");
Span.current().setAttribute("ai.preview.service_version", "application-version-here");
return "OK!";
}

@GetMapping("/test-annotations")
public String testAnnotations() {
return underAnnotation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ public void testApi() throws Exception {
assertTrue(rd.getSuccess());

assertEquals("myspanname", rdd.getName());
// ideally want these on rd, but can't get SERVER span yet

// ideally want the properties below on rd, but can't get SERVER span yet
// see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1726#issuecomment-731890267

// checking that instrumentation key, cloud role name, cloud role instance, and sdk version are from the agent
assertEquals("00000000-0000-0000-0000-0FEEDDADBEEF", rddEnvelope.getIKey());
assertEquals("testrolename", rddEnvelope.getTags().get("ai.cloud.role"));
assertEquals("testroleinstance", rddEnvelope.getTags().get("ai.cloud.roleInstance"));
assertTrue(rddEnvelope.getTags().get("ai.internal.sdkVersion").startsWith("java:3."));
assertEquals("myuser", rddEnvelope.getTags().get("ai.user.id"));
assertEquals("myvalue1", rdd.getProperties().get("myattr1"));
assertEquals("myvalue2", rdd.getProperties().get("myattr2"));
Expand All @@ -44,6 +51,40 @@ public void testApi() throws Exception {
assertParentChild(rd.getId(), rdEnvelope, rddEnvelope);
}

@Test
@TargetUri("/test-overriding-ikey-etc")
public void testOverridingIkeyEtc() throws Exception {
List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);

Envelope rdEnvelope = rdList.get(0);
String operationId = rdEnvelope.getTags().get("ai.operation.id");
List<Envelope> rddList = mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 1, operationId);
assertEquals(0, mockedIngestion.getCountForType("EventData"));

Envelope rddEnvelope = rddList.get(0);

RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
RemoteDependencyData rdd = (RemoteDependencyData) ((Data<?>) rddEnvelope.getData()).getBaseData();

assertEquals("GET /OpenTelemetryApiSupport/test-overriding-ikey-etc", rd.getName());
assertTrue(rd.getProperties().isEmpty());
assertTrue(rd.getSuccess());

// ideally want the properties below on rd, but can't get SERVER span yet
// see https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/1726#issuecomment-731890267

// checking that instrumentation key, cloud role name, cloud role instance, and sdk version are from the agent
assertEquals("12341234-1234-1234-1234-123412341234", rddEnvelope.getIKey());
assertEquals("role-name-here", rddEnvelope.getTags().get("ai.cloud.role"));
assertEquals("role-instance-here", rddEnvelope.getTags().get("ai.cloud.roleInstance"));
assertEquals("application-version-here", rddEnvelope.getTags().get("ai.application.ver"));
assertTrue(rddEnvelope.getTags().get("ai.internal.sdkVersion").startsWith("java:3."));
assertTrue(rdd.getProperties().isEmpty());
assertTrue(rdd.getSuccess());

assertParentChild(rd.getId(), rdEnvelope, rddEnvelope);
}

@Test
@TargetUri("/test-annotations")
public void testAnnotations() throws Exception {
Expand Down

0 comments on commit 0aac0ec

Please sign in to comment.