-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoServlet3InstrumentationModule.java
46 lines (39 loc) · 1.41 KB
/
DemoServlet3InstrumentationModule.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
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package com.example.javaagent.instrumentation;
import static java.util.Collections.singletonList;
import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;
/**
* This is a demo instrumentation which hooks into servlet invocation and modifies the http
* response.
*/
@AutoService(InstrumentationModule.class)
public final class DemoServlet3InstrumentationModule extends InstrumentationModule {
public DemoServlet3InstrumentationModule() {
super("servlet-demo", "servlet-3");
}
/*
We want this instrumentation to be applied after the standard servlet instrumentation.
The latter creates a server span around http request.
This instrumentation needs access to that server span.
*/
@Override
public int order() {
return 1;
}
@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return AgentElementMatchers.hasClassesNamed("javax.servlet.http.HttpServlet");
}
@Override
public List<TypeInstrumentation> typeInstrumentations() {
return singletonList(new DemoServlet3Instrumentation());
}
}