-
Notifications
You must be signed in to change notification settings - Fork 791
/
ServerAttributesExtractor.java
62 lines (54 loc) · 2.28 KB
/
ServerAttributesExtractor.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
57
58
59
60
61
62
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.api.instrumenter.network;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.FallbackAddressPortExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.network.internal.InternalServerAttributesExtractor;
import javax.annotation.Nullable;
/**
* Extractor of <a
* href="https://github.com/open-telemetry/semantic-conventions/blob/main/specification/trace/semantic_conventions/span-general.md#server-attributes">server
* attributes</a>.
*/
public final class ServerAttributesExtractor<REQUEST, RESPONSE>
implements AttributesExtractor<REQUEST, RESPONSE> {
/**
* Returns a new {@link ServerAttributesExtractor} that will use the passed {@link
* ServerAttributesGetter}.
*/
public static <REQUEST, RESPONSE> ServerAttributesExtractor<REQUEST, RESPONSE> create(
ServerAttributesGetter<REQUEST, RESPONSE> getter) {
return new ServerAttributesExtractor<>(getter);
}
private final InternalServerAttributesExtractor<REQUEST, RESPONSE> internalExtractor;
ServerAttributesExtractor(ServerAttributesGetter<REQUEST, RESPONSE> getter) {
// the ServerAttributesExtractor will always emit new semconv
internalExtractor =
new InternalServerAttributesExtractor<>(
getter,
(port, request) -> true,
FallbackAddressPortExtractor.noop(),
/* emitStableUrlAttributes= */ true,
/* emitOldHttpAttributes= */ false,
// this param does not matter when old semconv is off
InternalServerAttributesExtractor.Mode.HOST,
/* captureServerSocketAttributes= */ true);
}
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalExtractor.onStart(attributes, request);
}
@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
REQUEST request,
@Nullable RESPONSE response,
@Nullable Throwable error) {
internalExtractor.onEnd(attributes, request, response);
}
}