-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-15566 Opentelemetry changes using java agent #3445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
047144d
36a4699
4cd5a69
6c6afec
42f80ed
adc4360
d0f7bb6
1aed112
e643684
d9f8868
8b42eb2
9786414
e2e5fa9
f9996bb
b0cb50c
7465205
3129f61
64e4dfb
fb0a20b
38d276f
8d99d3a
1d42abd
6a67b4a
b106f39
9b167ef
ee5d869
4bdaa8e
08621d5
a05a50f
13584ca
de37111
e7e9b57
8589d78
877a934
f87ca27
9dd3d09
19bb247
a735d9d
792188a
ff4561b
e0fbb44
b8286c7
90318bd
8395a88
950c721
c651a30
1c67bde
63068eb
9ee6e3a
8154c9e
7581895
0a95820
dcb36d3
e002c41
37bbb37
e68f3df
9eecd03
c8f5788
a49ed1f
0b57ef9
ebfef3b
0e77ce3
78efa96
97ccfef
8394fe7
e9e2e07
4b3fcd2
09efd6a
e30e51f
5ebcefb
a02578f
1338051
d0c0f6a
d66302b
f2e09c4
adbe2f1
8fd6d47
a4d547b
b944ae2
e24fe6c
d914c1e
e31e4e4
d2ce8cb
0e55933
e7de0ca
727d8e6
72a9c64
3cbee6e
6e4d4f4
e76e46c
386072f
b3c30e9
fa83a9d
fe1ba90
6f1504b
5a34b3d
f6085a8
4ba3561
c1908a6
0d9a15b
584a531
66ef9d6
ac7f873
d360089
4d4da37
60cf4ba
6a6b999
31543fe
4d1b6fd
e17bd05
809ff97
20c1e20
c3e8039
8095b97
e903420
fab24cc
a9603e2
7176927
87457da
d879a39
84076ce
de59432
2abb688
e64e02b
73192a2
6f9bced
b12f3ec
b04b76b
5101205
1d9f6c0
a9c2aab
9c2df41
ecf9713
e9960b8
f2b3110
ec73be3
c06b3e9
5c3b4a1
1d9587f
4527d2f
347053d
f254f96
337ba17
3717ff3
526f946
3941cd8
e43c743
50c409c
bc2e34e
ae8302f
b5e787f
8faef36
afb0797
cb999d9
9cb3833
57a17d8
26bf2c5
1983d6a
72f756c
3d7ccf5
2bc7d0b
f5cf2f3
8a302d3
9c59c12
55bf7e9
0a7f46c
03dec53
8ac775d
a009895
ffc76d9
e48ed3d
ea2cf8c
a9448b2
14d0755
46b6892
643df58
beb66b2
5fda27a
23ce19a
bcb01d4
7670bfd
ce92818
cdff57c
75e02c4
fafa6df
aa6f709
434dc55
8949898
7ac0f7c
2f405dd
bfd42c4
138a360
b01edfb
f8120d2
de02c64
14262dd
90687c0
f15b813
99bebbf
7813961
0b93af8
881ddfb
560e910
229a1b6
f0b4c37
734d8c2
0a229ab
3d0b559
b8f9965
5dfe0ac
6750af5
70bd0f2
ec0f456
def0a11
5b812d3
544af0c
e1384b5
3eee20a
6703ca8
585ad60
b194902
409780f
69a28f4
81a02c0
0a672ea
d36cb10
08e8d7e
ad8041f
2b3bde9
ee6d496
a795d2f
95d639a
f03e77c
ca8c17c
cf52526
da0b400
0acf6b2
85ce2b3
a39d923
bb52290
9eaca6e
d78bcc5
88cd2aa
9f0c418
24cf3ab
32e5267
57ed0dd
ea2dc2c
a76aa87
78255c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,28 +17,54 @@ | |
| */ | ||
| package org.apache.hadoop.tracing; | ||
|
|
||
| import io.opentelemetry.context.Scope; | ||
|
|
||
| import java.io.Closeable; | ||
|
|
||
| public class Span implements Closeable { | ||
|
|
||
| private io.opentelemetry.api.trace.Span span = null; | ||
|
||
| public Span() { | ||
| } | ||
|
|
||
| public Span(io.opentelemetry.api.trace.Span span){ | ||
| this.span = span; | ||
| } | ||
|
|
||
| public Span addKVAnnotation(String key, String value) { | ||
| if(span != null){ | ||
| span.setAttribute(key, value); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public Span addTimelineAnnotation(String msg) { | ||
| if(span != null){ | ||
| span.addEvent(msg); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public SpanContext getContext() { | ||
| if(span != null){ | ||
| return new SpanContext(span.getSpanContext()); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| public void finish() { | ||
| close(); | ||
| } | ||
|
|
||
| public void close() { | ||
| if(span != null){ | ||
| span.end(); | ||
|
||
| } | ||
| } | ||
|
|
||
| public Scope makeCurrent() { | ||
steveloughran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if(span != null){ | ||
| return span.makeCurrent(); | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,75 @@ | |
| package org.apache.hadoop.tracing; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import io.opentelemetry.api.trace.Span; | ||
| import io.opentelemetry.api.trace.TraceFlags; | ||
| import io.opentelemetry.api.trace.TraceState; | ||
| import io.opentelemetry.api.trace.TraceStateBuilder; | ||
| import org.apache.hadoop.thirdparty.protobuf.ByteString; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Wrapper class for SpanContext to avoid using OpenTracing/OpenTelemetry | ||
| * SpanContext class directly for better separation. | ||
| */ | ||
| public class SpanContext implements Closeable { | ||
| public SpanContext() { | ||
| public class SpanContext implements Closeable { | ||
| public static final Logger LOG = LoggerFactory.getLogger(SpanContext.class.getName()); | ||
| private static final String TRACE_ID = "TRACE_ID"; | ||
| private static final String SPAN_ID = "SPAN_ID"; | ||
| private static final String TRACE_FLAGS = "TRACE_FLAGS"; | ||
|
|
||
|
|
||
| private io.opentelemetry.api.trace.SpanContext spanContext = null; | ||
|
||
| public SpanContext(io.opentelemetry.api.trace.SpanContext spanContext) { | ||
| this.spanContext = spanContext; | ||
| } | ||
|
|
||
| public void close() { | ||
|
|
||
| } | ||
|
|
||
| public Map<String, String> getKVSpanContext(){ | ||
| if(spanContext != null){ | ||
| //TODO: may we should move this to Proto | ||
| Map<String, String> kvMap = new HashMap<>(); | ||
| kvMap.put(TRACE_ID, spanContext.getTraceId()); | ||
| kvMap.put(SPAN_ID, spanContext.getSpanId()); | ||
| kvMap.put(TRACE_FLAGS, spanContext.getTraceFlags().asHex()); | ||
| kvMap.putAll(spanContext.getTraceState().asMap()); | ||
| return kvMap; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| static SpanContext buildFromKVMap(Map<String, String> kvMap){ | ||
| try{ | ||
| String traceId = kvMap.get(TRACE_ID); | ||
| String spanId = kvMap.get(SPAN_ID); | ||
| String traceFlagsHex = kvMap.get(TRACE_FLAGS); | ||
| TraceFlags traceFlags = TraceFlags.fromHex(traceFlagsHex, 0); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if traceFlagsHex isn't found? exit fast |
||
| TraceStateBuilder traceStateBuilder = TraceState.builder(); | ||
| for(Map.Entry<String, String> keyValue: kvMap.entrySet()){ | ||
| if(keyValue.getKey().equals(TRACE_ID) || keyValue.getKey().equals(SPAN_ID) || keyValue.getKey().equals(TRACE_FLAGS)){ | ||
| continue; | ||
| } | ||
| traceStateBuilder.put(keyValue.getKey(), keyValue.getValue()); | ||
| } | ||
| TraceState traceState = traceStateBuilder.build(); | ||
| io.opentelemetry.api.trace.SpanContext spanContext = io.opentelemetry.api.trace.SpanContext.createFromRemoteParent(traceId, spanId, traceFlags, traceState ); | ||
| return new SpanContext(spanContext); | ||
| } catch (Exception e){ | ||
| LOG.error("Error in processing remote context " + kvMap != null? kvMap.toString() : "", e); | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| public io.opentelemetry.api.trace.SpanContext getSpanContext() { | ||
| return spanContext; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.