Skip to content

Commit 411fa57

Browse files
Twilio metadata (#16312)
1 parent e06e2e9 commit 411fa57

5 files changed

Lines changed: 104 additions & 31 deletions

File tree

instrumentation-docs/instrumentations.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ readonly INSTRUMENTATIONS=(
259259
"tapestry-5.4:javaagent:test"
260260
"tomcat:tomcat-jdbc:javaagent:test"
261261
"tomcat:tomcat-jdbc:javaagent:testStableSemconv"
262+
"twilio-6.6:javaagent:test"
263+
"twilio-6.6:javaagent:testExperimental"
262264
"vertx:vertx-http-client:vertx-http-client-3.0:javaagent:test"
263265
"vertx:vertx-http-client:vertx-http-client-4.0:javaagent:test"
264266
"vertx:vertx-http-client:vertx-http-client-5.0:javaagent:test"

instrumentation/twilio-6.6/javaagent/build.gradle.kts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ dependencies {
2121
latestDepTestLibrary("com.twilio.sdk:twilio:7.+") // documented limitation
2222
}
2323

24-
tasks.withType<Test>().configureEach {
25-
// TODO run tests both with and without experimental span attributes
26-
jvmArgs("-Dotel.instrumentation.twilio.experimental-span-attributes=true")
24+
tasks {
25+
withType<Test>().configureEach {
26+
systemProperty("collectMetadata", findProperty("collectMetadata")?.toString() ?: "false")
27+
}
28+
29+
val testExperimental by registering(Test::class) {
30+
testClassesDirs = sourceSets.test.get().output.classesDirs
31+
classpath = sourceSets.test.get().runtimeClasspath
32+
33+
jvmArgs("-Dotel.instrumentation.twilio.experimental-span-attributes=true")
34+
systemProperty("metadataConfig", "otel.instrumentation.twilio.experimental-span-attributes=true")
35+
}
36+
37+
check {
38+
dependsOn(testExperimental)
39+
}
2740
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.twilio;
7+
8+
import javax.annotation.Nullable;
9+
10+
class ExperimentalTestHelper {
11+
private static final boolean isEnabled =
12+
Boolean.getBoolean("otel.instrumentation.twilio.experimental-span-attributes");
13+
14+
@Nullable
15+
static String experimental(String value) {
16+
if (isEnabled) {
17+
return value;
18+
}
19+
return null;
20+
}
21+
22+
private ExperimentalTestHelper() {}
23+
}

instrumentation/twilio-6.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/twilio/TwilioClientTest.java

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static io.opentelemetry.api.common.AttributeKey.stringKey;
99
import static io.opentelemetry.api.trace.SpanKind.CLIENT;
10+
import static io.opentelemetry.javaagent.instrumentation.twilio.ExperimentalTestHelper.experimental;
1011
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1112
import static java.nio.charset.StandardCharsets.UTF_8;
1213
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -169,11 +170,14 @@ void synchronousMessage() {
169170
.hasAttributesSatisfyingExactly(
170171
equalTo(
171172
stringKey("twilio.type"),
172-
"com.twilio.rest.api.v2010.account.Message"),
173+
experimental("com.twilio.rest.api.v2010.account.Message")),
173174
equalTo(
174-
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
175-
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
176-
equalTo(stringKey("twilio.status"), "sent"))));
175+
stringKey("twilio.account"),
176+
experimental("AC14984e09e497506cf0d5eb59b1f6ace7")),
177+
equalTo(
178+
stringKey("twilio.sid"),
179+
experimental("MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
180+
equalTo(stringKey("twilio.status"), experimental("sent")))));
177181
}
178182

179183
@Test
@@ -205,11 +209,15 @@ void synchronousCall() throws URISyntaxException {
205209
.hasParent(trace.getSpan(0))
206210
.hasAttributesSatisfyingExactly(
207211
equalTo(
208-
stringKey("twilio.type"), "com.twilio.rest.api.v2010.account.Call"),
212+
stringKey("twilio.type"),
213+
experimental("com.twilio.rest.api.v2010.account.Call")),
214+
equalTo(
215+
stringKey("twilio.account"),
216+
experimental("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
209217
equalTo(
210-
stringKey("twilio.account"), "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
211-
equalTo(stringKey("twilio.sid"), "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
212-
equalTo(stringKey("twilio.status"), "completed"))));
218+
stringKey("twilio.sid"),
219+
experimental("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
220+
equalTo(stringKey("twilio.status"), experimental("completed")))));
213221
}
214222

215223
@Test
@@ -250,11 +258,14 @@ void httpClient() throws IOException {
250258
.hasAttributesSatisfyingExactly(
251259
equalTo(
252260
stringKey("twilio.type"),
253-
"com.twilio.rest.api.v2010.account.Message"),
261+
experimental("com.twilio.rest.api.v2010.account.Message")),
262+
equalTo(
263+
stringKey("twilio.account"),
264+
experimental("AC14984e09e497506cf0d5eb59b1f6ace7")),
254265
equalTo(
255-
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
256-
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
257-
equalTo(stringKey("twilio.status"), "sent"))));
266+
stringKey("twilio.sid"),
267+
experimental("MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
268+
equalTo(stringKey("twilio.status"), experimental("sent")))));
258269
}
259270

260271
@SuppressWarnings("CannotMockMethod")
@@ -303,11 +314,14 @@ void httpClientRetry() throws IOException {
303314
.hasAttributesSatisfyingExactly(
304315
equalTo(
305316
stringKey("twilio.type"),
306-
"com.twilio.rest.api.v2010.account.Message"),
317+
experimental("com.twilio.rest.api.v2010.account.Message")),
307318
equalTo(
308-
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
309-
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
310-
equalTo(stringKey("twilio.status"), "sent"))));
319+
stringKey("twilio.account"),
320+
experimental("AC14984e09e497506cf0d5eb59b1f6ace7")),
321+
equalTo(
322+
stringKey("twilio.sid"),
323+
experimental("MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
324+
equalTo(stringKey("twilio.status"), experimental("sent")))));
311325
}
312326

313327
@Test
@@ -357,11 +371,14 @@ void httpClientRetryAsync() throws Exception {
357371
.hasAttributesSatisfyingExactly(
358372
equalTo(
359373
stringKey("twilio.type"),
360-
"com.twilio.rest.api.v2010.account.Message"),
374+
experimental("com.twilio.rest.api.v2010.account.Message")),
375+
equalTo(
376+
stringKey("twilio.account"),
377+
experimental("AC14984e09e497506cf0d5eb59b1f6ace7")),
361378
equalTo(
362-
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
363-
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
364-
equalTo(stringKey("twilio.status"), "sent"))));
379+
stringKey("twilio.sid"),
380+
experimental("MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
381+
equalTo(stringKey("twilio.status"), experimental("sent")))));
365382
}
366383

367384
@Test
@@ -424,11 +441,14 @@ void rootSpan() {
424441
.hasAttributesSatisfyingExactly(
425442
equalTo(
426443
stringKey("twilio.type"),
427-
"com.twilio.rest.api.v2010.account.Message"),
444+
experimental("com.twilio.rest.api.v2010.account.Message")),
428445
equalTo(
429-
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
430-
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
431-
equalTo(stringKey("twilio.status"), "sent"))));
446+
stringKey("twilio.account"),
447+
experimental("AC14984e09e497506cf0d5eb59b1f6ace7")),
448+
equalTo(
449+
stringKey("twilio.sid"),
450+
experimental("MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
451+
equalTo(stringKey("twilio.status"), experimental("sent")))));
432452
}
433453

434454
@Test
@@ -470,11 +490,14 @@ void asynchronousCall() throws Exception {
470490
.hasAttributesSatisfyingExactly(
471491
equalTo(
472492
stringKey("twilio.type"),
473-
"com.twilio.rest.api.v2010.account.Message"),
493+
experimental("com.twilio.rest.api.v2010.account.Message")),
494+
equalTo(
495+
stringKey("twilio.account"),
496+
experimental("AC14984e09e497506cf0d5eb59b1f6ace7")),
474497
equalTo(
475-
stringKey("twilio.account"), "AC14984e09e497506cf0d5eb59b1f6ace7"),
476-
equalTo(stringKey("twilio.sid"), "MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"),
477-
equalTo(stringKey("twilio.status"), "sent"))));
498+
stringKey("twilio.sid"),
499+
experimental("MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")),
500+
equalTo(stringKey("twilio.status"), experimental("sent")))));
478501
}
479502

480503
@Test
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
display_name: Twilio
2+
description: >
3+
This instrumentation enables client spans for Twilio SDK API calls such as sending messages and
4+
making phone calls.
5+
library_link: https://github.com/twilio/twilio-java
6+
configurations:
7+
- name: otel.instrumentation.twilio.experimental-span-attributes
8+
description: >
9+
Enables experimental span attributes `twilio.type`, `twilio.account`, `twilio.sid`, and
10+
`twilio.status`.
11+
type: boolean
12+
default: false

0 commit comments

Comments
 (0)