-
Notifications
You must be signed in to change notification settings - Fork 867
/
DemoSpanProcessor.java
56 lines (47 loc) · 1.5 KB
/
DemoSpanProcessor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package com.example.javaagent;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.sdk.trace.SpanProcessor;
import org.apache.commons.lang3.RandomStringUtils;
/**
* See <a
* href="https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#span-processor">
* OpenTelemetry Specification</a> for more information about {@link SpanProcessor}.
*
* @see DemoAutoConfigurationCustomizerProvider
*/
public class DemoSpanProcessor implements SpanProcessor {
@Override
public void onStart(Context parentContext, ReadWriteSpan span) {
/*
The sole purpose of this attribute is to introduce runtime dependency on some external library.
We need this to demonstrate how extension can use them.
*/
span.setAttribute("random", RandomStringUtils.random(10));
span.setAttribute("custom", "demo");
}
@Override
public boolean isStartRequired() {
return true;
}
@Override
public void onEnd(ReadableSpan span) {}
@Override
public boolean isEndRequired() {
return false;
}
@Override
public CompletableResultCode shutdown() {
return CompletableResultCode.ofSuccess();
}
@Override
public CompletableResultCode forceFlush() {
return CompletableResultCode.ofSuccess();
}
}