-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow optin for stable http attributes
- Loading branch information
1 parent
5fc866f
commit 5c86418
Showing
7 changed files
with
336 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...va/com/avioconsulting/mule/opentelemetry/internal/opentelemetry/sdk/SemconvStability.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.avioconsulting.mule.opentelemetry.internal.opentelemetry.sdk; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static java.util.Arrays.asList; | ||
|
||
/** | ||
* Reads the Semantic Convention stability flag. | ||
* Could have used | ||
* {@link io.opentelemetry.instrumentation.api.internal.SemconvStability} but | ||
* that is marked as internal | ||
* so replicating it here for now. | ||
*/ | ||
public class SemconvStability { | ||
|
||
private static boolean emitOldHttpSemconv; | ||
private static boolean emitStableHttpSemconv; | ||
private static boolean emitOldJvmSemconv; | ||
private static boolean emitStableJvmSemconv; | ||
|
||
static { | ||
init(); | ||
} | ||
|
||
public static void init() { | ||
boolean oldHttp = true; | ||
boolean stableHttp = false; | ||
boolean oldJvm = true; | ||
boolean stableJvm = false; | ||
|
||
String value = System.getProperty("otel.semconv-stability.opt-in", | ||
System.getenv("OTEL_SEMCONV_STABILITY_OPT_IN")); | ||
|
||
if (value != null) { | ||
Set<String> values = new HashSet<>(asList(value.split(","))); | ||
if (values.contains("http")) { | ||
oldHttp = false; | ||
stableHttp = true; | ||
} | ||
// no else -- technically it's possible to set "http,http/dup", in which case we | ||
// should emit | ||
// both sets of attributes | ||
if (values.contains("http/dup")) { | ||
oldHttp = true; | ||
stableHttp = true; | ||
} | ||
|
||
if (values.contains("jvm")) { | ||
oldJvm = false; | ||
stableJvm = true; | ||
} | ||
if (values.contains("jvm/dup")) { | ||
oldJvm = true; | ||
stableJvm = true; | ||
} | ||
} | ||
|
||
emitOldHttpSemconv = oldHttp; | ||
emitStableHttpSemconv = stableHttp; | ||
emitOldJvmSemconv = oldJvm; | ||
emitStableJvmSemconv = stableJvm; | ||
} | ||
|
||
public static boolean emitOldHttpSemconv() { | ||
return emitOldHttpSemconv; | ||
} | ||
|
||
public static boolean emitStableHttpSemconv() { | ||
return emitStableHttpSemconv; | ||
} | ||
|
||
public static boolean emitOldJvmSemconv() { | ||
return emitOldJvmSemconv; | ||
} | ||
|
||
public static boolean emitStableJvmSemconv() { | ||
return emitStableJvmSemconv; | ||
} | ||
|
||
private SemconvStability() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...a/com/avioconsulting/mule/opentelemetry/MuleOpenTelemetryHttpOldStableAttributesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.avioconsulting.mule.opentelemetry; | ||
|
||
import com.avioconsulting.mule.opentelemetry.internal.opentelemetry.sdk.test.DelegatedLoggingSpanTestExporter; | ||
import org.assertj.core.api.InstanceOfAssertFactories; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.as; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
public class MuleOpenTelemetryHttpOldStableAttributesTest extends AbstractMuleArtifactTraceTest { | ||
|
||
@Override | ||
protected void doSetUpBeforeMuleContextCreation() throws Exception { | ||
System.setProperty("otel.semconv-stability.opt-in", "http/dup"); | ||
super.doSetUpBeforeMuleContextCreation(); | ||
} | ||
|
||
@Override | ||
protected void doTearDownAfterMuleContextDispose() throws Exception { | ||
System.clearProperty("otel.semconv-stability.opt-in"); | ||
super.doTearDownAfterMuleContextDispose(); | ||
} | ||
|
||
@Override | ||
protected String getConfigFile() { | ||
return "mule-opentelemetry-http.xml"; | ||
} | ||
|
||
@Test | ||
public void testOldAndStableHttpAttributes() throws Exception { | ||
System.setProperty("otel.semconv-stability.opt-in", "http/dup"); | ||
sendRequest(CORRELATION_ID, "test-remote-request", 200); | ||
await().untilAsserted(() -> assertThat(DelegatedLoggingSpanTestExporter.spanQueue) | ||
.isNotEmpty() | ||
.hasSize(3)); | ||
assertThat(DelegatedLoggingSpanTestExporter.spanQueue) | ||
.filteredOnAssertions(span -> assertThat(span) | ||
.as("Span for http:listener flow") | ||
.extracting("spanName", "spanKind") | ||
.containsOnly("/test-remote-request", "SERVER")) | ||
.isNotEmpty() | ||
.hasSize(1) | ||
.element(0) | ||
.extracting("attributes", as(InstanceOfAssertFactories.map(String.class, Object.class))) | ||
.hasSizeGreaterThanOrEqualTo(13) | ||
.containsEntry("mule.app.flow.name", "mule-opentelemetry-app-requester-remote") | ||
.containsKey("mule.serverId") | ||
.containsEntry("http.scheme", "http") | ||
.containsEntry("http.method", "GET") | ||
.containsEntry("http.route", "/test-remote-request") | ||
.containsKey("mule.correlationId") | ||
.containsKey("http.user_agent") | ||
.hasEntrySatisfying("http.host", | ||
value -> assertThat(value.toString()).startsWith("localhost:")) | ||
.containsEntry("http.flavor", "1.1") | ||
.containsEntry("mule.app.flow.source.name", "listener") | ||
.containsEntry("mule.app.flow.source.namespace", "http") | ||
.containsEntry("mule.app.flow.source.configRef", "HTTP_Listener_config") | ||
.containsEntry("server.address", "localhost") | ||
.containsEntry("server.port", serverPort.getValue()) | ||
.containsEntry("http.route", "/test-remote-request") | ||
.containsEntry("http.request.method", "GET") | ||
.containsEntry("url.path", "/test-remote-request") | ||
.doesNotContainKey("url.query") | ||
.containsEntry("url.scheme", "http") | ||
.containsKey("user_agent.original") | ||
.containsKey("mule.correlationId"); | ||
System.clearProperty("otel.semconv-stability.opt-in"); | ||
} | ||
|
||
private void resetStaticFinalFields() { | ||
|
||
} | ||
} |
Oops, something went wrong.