Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion buildscripts/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
-->

<module name="TreeWalker">
<!-- Enforce static imports for OpenTelemetryAssertions methods (lowercase), but allow inner classes (uppercase) and imports -->
<module name="RegexpSinglelineJava">
<property name="format"
value="(?&lt;!import static io.opentelemetry.sdk.testing.assertj.)OpenTelemetryAssertions\."/>
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need a negative lookahead here? would it work without?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the negative lookback it catches lines like import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

[ant:checkstyle] [WARN] /Users/jaydeluca/code/projects/opentelemetry-java-instrumentation/instrumentation/ca
mel-2.20/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ExperimentalTest.jav
a:8: Please statically import methods from OpenTelemetryAssertions [RegexpSinglelineJava]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, got it now - maybe it's worth to add a comment explaining that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added a comment here, do you have a suggestion on how it could be more clear? I tried to explain it with the

but allow inner classes (uppercase) and imports

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>
<!-- negative lookahead for "import", because imports are handled by the rule below -->
value="^(?!.*import).*OpenTelemetryAssertions\.[a-z]"/>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the rule below is only for assertThat methods, but I pushed an update that calls out the lookahead being to exclude imports

<property name="message"
value="Please statically import methods from OpenTelemetryAssertions"/>
</module>
Expand Down
109 changes: 109 additions & 0 deletions docs/instrumentation-list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,115 @@ libraries:
Enable the capture of experimental `camel.uri`, `camel.kafka.partitionKey`, `camel.kafka.key` and `camel.kafka.offset` span attributes.
type: boolean
default: false
telemetry:
- when: default
spans:
- span_kind: CLIENT
attributes:
- name: db.name
type: STRING
- name: db.statement
type: STRING
- name: db.system
type: STRING
- name: http.request.method
type: STRING
- name: http.response.status_code
type: LONG
- name: url.full
type: STRING
- span_kind: INTERNAL
attributes:
- name: http.request.method
type: STRING
- name: messaging.destination.name
type: STRING
- name: messaging.message.id
type: STRING
- name: url.full
type: STRING
- span_kind: SERVER
attributes:
- name: http.request.method
type: STRING
- name: http.response.status_code
type: LONG
- name: url.full
type: STRING
- when: otel.instrumentation.camel.experimental-span-attributes=true
spans:
- span_kind: CLIENT
attributes:
- name: camel.uri
type: STRING
- name: db.name
type: STRING
- name: db.statement
type: STRING
- name: db.system
type: STRING
- name: http.request.method
type: STRING
- name: http.response.status_code
type: LONG
- name: url.full
type: STRING
- span_kind: INTERNAL
attributes:
- name: camel.uri
type: STRING
- name: http.request.method
type: STRING
- name: messaging.destination.name
type: STRING
- name: messaging.message.id
type: STRING
- name: url.full
type: STRING
- span_kind: SERVER
attributes:
- name: camel.uri
type: STRING
- name: http.request.method
type: STRING
- name: http.response.status_code
type: LONG
- name: url.full
type: STRING
- when: otel.semconv-stability.opt-in=database
spans:
- span_kind: CLIENT
attributes:
- name: db.namespace
type: STRING
- name: db.query.text
type: STRING
- name: db.system.name
type: STRING
- name: http.request.method
type: STRING
- name: http.response.status_code
type: LONG
- name: url.full
type: STRING
- span_kind: INTERNAL
attributes:
- name: http.request.method
type: STRING
- name: messaging.destination.name
type: STRING
- name: messaging.message.id
type: STRING
- name: url.full
type: STRING
- span_kind: SERVER
attributes:
- name: http.request.method
type: STRING
- name: http.response.status_code
type: LONG
- name: url.full
type: STRING
cassandra:
- name: cassandra-3.0
description: |
Expand Down
3 changes: 3 additions & 0 deletions instrumentation-docs/instrumentations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ readonly INSTRUMENTATIONS=(
"cassandra:cassandra-4.0:javaagent:testStableSemconv"
"cassandra:cassandra-4.4:javaagent:test"
"cassandra:cassandra-4.4:javaagent:testStableSemconv"
"camel-2.20:javaagent:test"
"camel-2.20:javaagent:testStableSemconv"
"camel-2.20:javaagent:testExperimental"
)

# Some instrumentation test suites don't run ARM, so we use colima to run them in an x86_64
Expand Down
12 changes: 9 additions & 3 deletions instrumentation/camel-2.20/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ dependencies {

tasks {
withType<Test>().configureEach {
// TODO run tests both with and without experimental span attributes
jvmArgs("-Dotel.instrumentation.camel.experimental-span-attributes=true")
jvmArgs("-Dotel.instrumentation.aws-sdk.experimental-span-attributes=true")

// TODO: fix camel instrumentation so that it uses semantic attributes extractors
Expand All @@ -81,14 +79,22 @@ tasks {
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")

jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")

systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
}

val testExperimental by registering(Test::class) {
jvmArgs("-Dotel.instrumentation.camel.experimental-span-attributes=true")
systemProperty("metadataConfig", "otel.instrumentation.camel.experimental-span-attributes=true")
}

val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=database")
systemProperty("metadataConfig", "otel.semconv-stability.opt-in=database")
}

check {
dependsOn(testStableSemconv)
dependsOn(testStableSemconv, testExperimental)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.apachecamel;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

import io.opentelemetry.api.trace.SpanKind;
Expand Down Expand Up @@ -70,12 +71,12 @@ void simpleDirectToSingleService() {
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://input")),
equalTo(stringKey("camel.uri"), experimental("direct://input"))),
span ->
span.hasName("receiver")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://receiver"))));
equalTo(stringKey("camel.uri"), experimental("direct://receiver")))));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apachecamel;

import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.sdk.testing.assertj.AttributeAssertion;
import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.StringAssertConsumer;

public class ExperimentalTest {
private static final String EXPERIMENTAL_FLAG =
"otel.instrumentation.camel.experimental-span-attributes";

public static String experimental(String value) {
if (!Boolean.getBoolean(EXPERIMENTAL_FLAG)) {
return null;
}
return value;
}

static AttributeAssertion experimentalSatisfies(
AttributeKey<String> key, StringAssertConsumer assertion) {
if (Boolean.getBoolean(EXPERIMENTAL_FLAG)) {
return satisfies(key, assertion);
} else {
return equalTo(key, null);
}
}

private ExperimentalTest() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.apachecamel;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;

import io.opentelemetry.api.trace.SpanKind;
Expand Down Expand Up @@ -70,18 +71,18 @@ void parallelMulticastToTwoChildServices() {
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://input")),
equalTo(stringKey("camel.uri"), experimental("direct://input"))),
span ->
span.hasName("first")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://first")),
equalTo(stringKey("camel.uri"), experimental("direct://first"))),
span ->
span.hasName("second")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://second"))));
equalTo(stringKey("camel.uri"), experimental("direct://second")))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package io.opentelemetry.javaagent.instrumentation.apachecamel;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimentalSatisfies;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.ClientAttributes.CLIENT_ADDRESS;
Expand Down Expand Up @@ -92,15 +94,15 @@ void restComponentServerAndClientCallWithJettyBackend() {
span.hasName("start")
.hasKind(SpanKind.INTERNAL)
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://start")),
equalTo(stringKey("camel.uri"), experimental("direct://start"))),
span ->
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(
stringKey("camel.uri"),
"rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D"),
experimental("rest://get:api/%7Bmodule%7D/unit/%7BunitId%7D")),
equalTo(HTTP_REQUEST_METHOD, "GET"),
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L)),
span ->
Expand Down Expand Up @@ -129,13 +131,13 @@ void restComponentServerAndClientCallWithJettyBackend() {
equalTo(
URL_FULL,
"http://localhost:" + port + "/api/firstModule/unit/unitOne"),
satisfies(
experimentalSatisfies(
stringKey("camel.uri"), val -> val.isInstanceOf(String.class))),
span ->
span.hasName("moduleUnit")
.hasKind(SpanKind.INTERNAL)
.hasParent(trace.getSpan(3))
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://moduleUnit"))));
equalTo(stringKey("camel.uri"), experimental("direct://moduleUnit")))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.apachecamel;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD;
import static io.opentelemetry.semconv.UrlAttributes.URL_FULL;
Expand Down Expand Up @@ -56,7 +57,7 @@ protected void cleanUp() {
}

@Test
public void singleCamelServiceSpan() {
void singleCamelServiceSpan() {
URI requestUrl = address.resolve("/camelService");

client.post(requestUrl.toString(), "testContent").aggregate().join();
Expand All @@ -72,6 +73,7 @@ public void singleCamelServiceSpan() {
equalTo(URL_FULL, requestUrl.toString()),
equalTo(
stringKey("camel.uri"),
requestUrl.toString().replace("localhost", "0.0.0.0")))));
experimental(
requestUrl.toString().replace("localhost", "0.0.0.0"))))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.opentelemetry.javaagent.instrumentation.apachecamel;

import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static io.opentelemetry.javaagent.instrumentation.apachecamel.ExperimentalTest.experimental;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.ClientAttributes.CLIENT_ADDRESS;
Expand Down Expand Up @@ -111,7 +112,7 @@ void twoCamelServiceSpans() throws Exception {
.hasKind(SpanKind.INTERNAL)
.hasNoParent()
.hasAttributesSatisfyingExactly(
equalTo(stringKey("camel.uri"), "direct://input")),
equalTo(stringKey("camel.uri"), experimental("direct://input"))),
span ->
span.hasName("POST")
.hasKind(SpanKind.CLIENT)
Expand All @@ -122,7 +123,7 @@ void twoCamelServiceSpans() throws Exception {
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L),
equalTo(
stringKey("camel.uri"),
"http://localhost:" + portOne + "/serviceOne")),
experimental("http://localhost:" + portOne + "/serviceOne"))),
span ->
span.hasName("POST /serviceOne")
.hasKind(SpanKind.SERVER)
Expand All @@ -133,7 +134,7 @@ void twoCamelServiceSpans() throws Exception {
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L),
equalTo(
stringKey("camel.uri"),
"http://0.0.0.0:" + portOne + "/serviceOne")),
experimental("http://0.0.0.0:" + portOne + "/serviceOne"))),
span ->
span.hasName("POST")
.hasKind(SpanKind.CLIENT)
Expand All @@ -144,7 +145,7 @@ void twoCamelServiceSpans() throws Exception {
equalTo(HTTP_RESPONSE_STATUS_CODE, 200L),
equalTo(
stringKey("camel.uri"),
"http://127.0.0.1:" + portTwo + "/serviceTwo")),
experimental("http://127.0.0.1:" + portTwo + "/serviceTwo"))),
span ->
span.hasName("POST /serviceTwo")
.hasKind(SpanKind.SERVER)
Expand All @@ -171,6 +172,9 @@ void twoCamelServiceSpans() throws Exception {
equalTo(URL_FULL, "http://127.0.0.1:" + portTwo + "/serviceTwo"),
equalTo(
stringKey("camel.uri"),
"jetty:http://0.0.0.0:" + portTwo + "/serviceTwo?arg=value"))));
experimental(
"jetty:http://0.0.0.0:"
+ portTwo
+ "/serviceTwo?arg=value")))));
}
}
Loading
Loading