Skip to content

Commit 8fc0a39

Browse files
committed
Update to latest opentelemetry-java-instrumentation
1 parent 8872f5b commit 8fc0a39

File tree

12 files changed

+105
-75
lines changed

12 files changed

+105
-75
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[submodule "opentelemetry-auto-instr-java"]
2-
path = opentelemetry-auto-instr-java
3-
url = https://github.com/trask/opentelemetry-auto-instr-java
1+
[submodule "opentelemetry-java-instrumentation"]
2+
path = opentelemetry-java-instrumentation
3+
url = https://github.com/trask/opentelemetry-java-instrumentation
44
branch = applicationinsights

agent/agent-bootstrap/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ task generateVersionProperties(type: PropsFileGen) {
2424
processResources.dependsOn generateVersionProperties
2525

2626
dependencies {
27-
compile (group: 'io.opentelemetry.auto', name: 'auto-bootstrap', version: '0.5.0-SNAPSHOT') {
27+
compile (group: 'io.opentelemetry.instrumentation.auto', name: 'opentelemetry-auto-auto-bootstrap', version: '0.5.0-SNAPSHOT') {
2828
exclude group: 'org.slf4j', module: 'slf4j-simple'
2929
}
3030
compile 'ch.qos.logback:logback-classic:1.2.3'

agent/agent-tooling/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ dependencies {
3737

3838
compile 'com.google.guava:guava:27.1-android'
3939

40-
compile 'io.opentelemetry.auto:auto-tooling:0.5.0-SNAPSHOT'
40+
compile 'io.opentelemetry.instrumentation.auto:opentelemetry-auto-auto-tooling:0.5.0-SNAPSHOT'
41+
// TODO sync bytebuddy version with version from auto-tooling (above)
42+
compile group: 'net.bytebuddy', name: 'byte-buddy', version: '1.10.10'
43+
4144
compile 'org.checkerframework:checker-qual-android:3.1.0'
4245

4346
compile(project(':core')) {

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/sampling/FixedRateSampler.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.common.collect.ImmutableMap;
44
import io.opentelemetry.common.AttributeValue;
5+
import io.opentelemetry.common.Attributes;
6+
import io.opentelemetry.common.ReadableAttributes;
57
import io.opentelemetry.sdk.trace.Sampler;
68
import io.opentelemetry.trace.Link;
79
import io.opentelemetry.trace.Span;
@@ -29,17 +31,18 @@ public final class FixedRateSampler implements Sampler {
2931

3032
public FixedRateSampler(double samplingPercentage) {
3133
this.samplingPercentage = samplingPercentage;
32-
alwaysOnDecision = new FixedRateSamplerDecision(true, ImmutableMap.of("ai.sampling.percentage",
33-
AttributeValue.doubleAttributeValue(samplingPercentage)));
34-
alwaysOffDecision= new FixedRateSamplerDecision(false, Collections.<String, AttributeValue>emptyMap());
34+
Attributes attributes = Attributes.of("ai.sampling.percentage",
35+
AttributeValue.doubleAttributeValue(samplingPercentage));
36+
alwaysOnDecision = new FixedRateSamplerDecision(true, attributes);
37+
alwaysOffDecision= new FixedRateSamplerDecision(false, Attributes.empty());
3538
}
3639

3740
@Override
3841
public Decision shouldSample(@Nullable SpanContext parentContext,
3942
TraceId traceId,
4043
String name,
4144
Span.Kind spanKind,
42-
Map<String, AttributeValue> attributes,
45+
ReadableAttributes attributes,
4346
List<Link> parentLinks) {
4447
if (SamplingScoreGeneratorV2.getSamplingScore(traceId.toLowerBase16()) >= samplingPercentage) {
4548
logger.debug("Item {} sampled out", name);
@@ -56,9 +59,9 @@ public String getDescription() {
5659
private static final class FixedRateSamplerDecision implements Decision {
5760

5861
private final boolean sampled;
59-
private final Map<String, AttributeValue> attributes;
62+
private final Attributes attributes;
6063

61-
private FixedRateSamplerDecision(boolean sampled, Map<String, AttributeValue> attributes) {
64+
private FixedRateSamplerDecision(boolean sampled, Attributes attributes) {
6265
this.sampled = sampled;
6366
this.attributes = attributes;
6467
}
@@ -69,7 +72,7 @@ public boolean isSampled() {
6972
}
7073

7174
@Override
72-
public Map<String, AttributeValue> getAttributes() {
75+
public Attributes getAttributes() {
7376
return attributes;
7477
}
7578
}

agent/agent/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ processResources {
3636
dependsOn ':agent:instrumentation:shadowJar'
3737

3838
from(zipTree(tasks.getByPath(':agent:instrumentation:shadowJar').archivePath)) {
39-
into 'auto-tooling-and-instrumentation.isolated'
39+
into 'inst'
4040
rename '(^.*)\\.class$', '$1.classdata'
4141
}
4242
}

agent/agent/jar_contents.regex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ com/microsoft/applicationinsights/agent/.*
55
io/
66
io/opentelemetry/
77
io/opentelemetry/auto/.*
8-
io/opentelemetry/contrib/
9-
io/opentelemetry/contrib/auto/.*
108
META-INF/
119
META-INF/MANIFEST\.MF
1210
LICENSE
@@ -21,4 +19,4 @@ rp-logger-config/diagnostics\.appender\.xml
2119
rp-logger-config/etw.appender\.xml
2220
applicationinsights-java-etw-provider-x86-64\.dll
2321
applicationinsights-java-etw-provider-x86\.dll
24-
auto-tooling-and-instrumentation.isolated/.*
22+
inst/.*

agent/exporter/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ repositories {
99
}
1010

1111
dependencies {
12-
compile 'io.opentelemetry:opentelemetry-sdk:0.5.0'
12+
compile 'io.opentelemetry:opentelemetry-sdk:0.6.0'
1313

1414
// this is needed in order to access AiAppId in auto-bootstrap for appId exchange data
15-
compileOnly 'io.opentelemetry.auto:auto-bootstrap:0.5.0-SNAPSHOT'
15+
compileOnly 'io.opentelemetry.instrumentation.auto:opentelemetry-auto-auto-bootstrap:0.5.0-SNAPSHOT'
1616

1717
compile 'org.slf4j:slf4j-api:1.7.26'
1818

agent/exporter/src/main/java/com/microsoft/applicationinsights/agent/Exporter.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
import io.opentelemetry.auto.bootstrap.instrumentation.aiappid.AiAppId;
4848
import io.opentelemetry.common.AttributeValue;
4949
import io.opentelemetry.common.AttributeValue.Type;
50+
import io.opentelemetry.common.Attributes;
51+
import io.opentelemetry.common.ReadableAttributes;
52+
import io.opentelemetry.common.ReadableKeyValuePairs.KeyValueConsumer;
5053
import io.opentelemetry.sdk.trace.data.SpanData;
5154
import io.opentelemetry.sdk.trace.data.SpanData.Event;
5255
import io.opentelemetry.sdk.trace.data.SpanData.Link;
@@ -125,7 +128,7 @@ private void exportRequest(String stdComponent, SpanData span) {
125128

126129
RequestTelemetry telemetry = new RequestTelemetry();
127130

128-
Map<String, AttributeValue> attributes = new HashMap<>(span.getAttributes());
131+
Map<String, AttributeValue> attributes = getAttributesCopy(span.getAttributes());
129132

130133
String sourceAppId = removeAttributeString(attributes, AiAppId.SPAN_SOURCE_ATTRIBUTE_NAME);
131134
if (!AiAppId.getAppId().equals(sourceAppId)) {
@@ -204,6 +207,17 @@ private void exportRequest(String stdComponent, SpanData span) {
204207
}
205208
}
206209

210+
private Map<String, AttributeValue> getAttributesCopy(ReadableAttributes attributes) {
211+
final Map<String, AttributeValue> copy = new HashMap<>();
212+
attributes.forEach(new KeyValueConsumer<AttributeValue>() {
213+
@Override
214+
public void consume(String key, AttributeValue value) {
215+
copy.put(key, value);
216+
}
217+
});
218+
return copy;
219+
}
220+
207221
private void exportRemoteDependency(String stdComponent, SpanData span, boolean inProc) {
208222

209223
RemoteDependencyTelemetry telemetry = new RemoteDependencyTelemetry();
@@ -214,7 +228,7 @@ private void exportRemoteDependency(String stdComponent, SpanData span, boolean
214228

215229
span.getInstrumentationLibraryInfo().getName();
216230

217-
Map<String, AttributeValue> attributes = new HashMap<>(span.getAttributes());
231+
Map<String, AttributeValue> attributes = getAttributesCopy(span.getAttributes());
218232

219233
if (inProc) {
220234
telemetry.setType("InProc");
@@ -278,7 +292,7 @@ private void exportRemoteDependency(String stdComponent, SpanData span, boolean
278292
}
279293

280294
private void exportLogSpan(SpanData span) {
281-
Map<String, AttributeValue> attributes = new HashMap<>(span.getAttributes());
295+
Map<String, AttributeValue> attributes = getAttributesCopy(span.getAttributes());
282296
String message = removeAttributeString(attributes, "message");
283297
String level = removeAttributeString(attributes, "level");
284298
String loggerName = removeAttributeString(attributes, "loggerName");
@@ -469,6 +483,18 @@ private static void addExtraAttributes(Map<String, String> properties, Map<Strin
469483
}
470484
}
471485

486+
private static void addExtraAttributes(final Map<String, String> properties, Attributes attributes) {
487+
attributes.forEach(new KeyValueConsumer<AttributeValue>() {
488+
@Override
489+
public void consume(String key, AttributeValue value) {
490+
String val = getStringValue(value);
491+
if (val != null) {
492+
properties.put(key, val);
493+
}
494+
}
495+
});
496+
}
497+
472498
private static Double removeAiSamplingPercentage(Map<String, AttributeValue> attributes) {
473499
return removeAttributeDouble(attributes, "ai.sampling.percentage");
474500
}

0 commit comments

Comments
 (0)