Skip to content

Commit 4f9c2d8

Browse files
Adds Micrometer Observation instrumentation (#401)
1 parent 9a62d72 commit 4f9c2d8

56 files changed

Lines changed: 2622 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/plugins-jdk17-test.0.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
matrix:
6060
case:
6161
- jdk17-with-gson-scenario
62+
# TODO: We can't test it just yet, because it requires a Skywalking release
63+
# - resttemplate-6.x-scenario
6264
steps:
6365
- uses: actions/checkout@v2
6466
with:

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Release Notes.
1616
* Report the agent version to OAP as an instance attribute
1717
* Polish jedis-4.x-plugin to change command to lowercase, which is consistent with jedis-2.x-3.x-plugin
1818
* Add micronauthttpclient,micronauthttpserver,memcached,ehcache,guavacache,jedis,redisson plugin config properties to agent.config
19+
* Add [Micrometer Observation](https://github.com/micrometer-metrics/micrometer/) support
1920
* Add tags `mq.message.keys` and `mq.message.tags` for RocketMQ producer span
2021

2122
#### Documentation
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!--
2+
~ Licensed to the Apache Software Foundation (ASF) under one or more
3+
~ contributor license agreements. See the NOTICE file distributed with
4+
~ this work for additional information regarding copyright ownership.
5+
~ The ASF licenses this file to You under the Apache License, Version 2.0
6+
~ (the "License"); you may not use this file except in compliance with
7+
~ the License. You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<parent>
21+
<artifactId>apm-application-toolkit</artifactId>
22+
<groupId>org.apache.skywalking</groupId>
23+
<version>8.14.0-SNAPSHOT</version>
24+
</parent>
25+
<modelVersion>4.0.0</modelVersion>
26+
27+
<artifactId>apm-toolkit-micrometer-1.10</artifactId>
28+
<packaging>jar</packaging>
29+
30+
<url>http://maven.apache.org</url>
31+
32+
<properties>
33+
<micrometer-core.version>1.10.2</micrometer-core.version>
34+
<context-propagation.version>1.0.0</context-propagation.version>
35+
</properties>
36+
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.apache.skywalking</groupId>
40+
<artifactId>apm-toolkit-micrometer-registry</artifactId>
41+
<version>${project.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>io.micrometer</groupId>
45+
<artifactId>micrometer-observation</artifactId>
46+
<version>${micrometer-core.version}</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>io.micrometer</groupId>
50+
<artifactId>micrometer-core</artifactId>
51+
<version>${micrometer-core.version}</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>io.micrometer</groupId>
55+
<artifactId>context-propagation</artifactId>
56+
<version>${context-propagation.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>io.micrometer</groupId>
60+
<artifactId>micrometer-test</artifactId>
61+
<version>${micrometer-core.version}</version>
62+
<scope>test</scope>
63+
</dependency>
64+
</dependencies>
65+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.toolkit.micrometer.observation;
20+
21+
import io.micrometer.context.ThreadLocalAccessor;
22+
23+
/**
24+
* A {@link ThreadLocalAccessor} to put and restore current {@code ContextSnapshot} from APM agent.
25+
*/
26+
public class SkywalkingContextSnapshotThreadLocalAccessor implements ThreadLocalAccessor<Object> {
27+
28+
/**
29+
* Key under which ContextSnapshot is being registered.
30+
*/
31+
public static final String KEY = "skywalking.contextsnapshot";
32+
33+
@Override
34+
public Object key() {
35+
return KEY;
36+
}
37+
38+
// Type will be ContextSnapshot
39+
@Override
40+
public Object getValue() {
41+
return null;
42+
}
43+
44+
// Object to set will be ContextSnapshot
45+
@Override
46+
public void setValue(Object value) {
47+
48+
}
49+
50+
@Override
51+
public void reset() {
52+
53+
}
54+
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.toolkit.micrometer.observation;
20+
21+
import io.micrometer.observation.Observation;
22+
import io.micrometer.observation.ObservationHandler;
23+
24+
public class SkywalkingDefaultTracingHandler implements ObservationHandler<Observation.Context> {
25+
@Override
26+
public boolean supportsContext(final Observation.Context context) {
27+
return true;
28+
}
29+
30+
@Override
31+
public void onStart(final Observation.Context context) {
32+
33+
}
34+
35+
@Override
36+
public void onError(final Observation.Context context) {
37+
38+
}
39+
40+
@Override
41+
public void onEvent(final Observation.Event event, final Observation.Context context) {
42+
43+
}
44+
45+
@Override
46+
public void onScopeOpened(final Observation.Context context) {
47+
48+
}
49+
50+
@Override
51+
public void onScopeClosed(final Observation.Context context) {
52+
53+
}
54+
55+
@Override
56+
public void onStop(final Observation.Context context) {
57+
58+
}
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.toolkit.micrometer.observation;
20+
21+
import io.micrometer.core.instrument.observation.DefaultMeterObservationHandler;
22+
import org.apache.skywalking.apm.meter.micrometer.SkywalkingMeterRegistry;
23+
24+
public class SkywalkingMeterHandler extends DefaultMeterObservationHandler {
25+
26+
public SkywalkingMeterHandler(SkywalkingMeterRegistry meterRegistry) {
27+
super(meterRegistry);
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.toolkit.micrometer.observation;
20+
21+
import io.micrometer.observation.Observation;
22+
import io.micrometer.observation.ObservationHandler;
23+
import io.micrometer.observation.transport.ReceiverContext;
24+
25+
public class SkywalkingReceiverTracingHandler implements ObservationHandler<ReceiverContext<?>> {
26+
@Override
27+
public boolean supportsContext(final Observation.Context context) {
28+
return context instanceof ReceiverContext;
29+
}
30+
31+
@Override
32+
public void onStart(final ReceiverContext<?> context) {
33+
34+
}
35+
36+
@Override
37+
public void onError(final ReceiverContext<?> context) {
38+
39+
}
40+
41+
@Override
42+
public void onEvent(final Observation.Event event, final ReceiverContext<?> context) {
43+
44+
}
45+
46+
@Override
47+
public void onScopeOpened(final ReceiverContext<?> context) {
48+
49+
}
50+
51+
@Override
52+
public void onScopeClosed(final ReceiverContext<?> context) {
53+
54+
}
55+
56+
@Override
57+
public void onStop(final ReceiverContext<?> context) {
58+
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.skywalking.apm.toolkit.micrometer.observation;
20+
21+
import io.micrometer.observation.Observation;
22+
import io.micrometer.observation.ObservationHandler;
23+
import io.micrometer.observation.transport.SenderContext;
24+
25+
public class SkywalkingSenderTracingHandler implements ObservationHandler<SenderContext<?>> {
26+
@Override
27+
public boolean supportsContext(final Observation.Context context) {
28+
return context instanceof SenderContext;
29+
}
30+
31+
@Override
32+
public void onStart(final SenderContext<?> context) {
33+
34+
}
35+
36+
@Override
37+
public void onError(final SenderContext<?> context) {
38+
39+
}
40+
41+
@Override
42+
public void onEvent(final Observation.Event event, final SenderContext<?> context) {
43+
44+
}
45+
46+
@Override
47+
public void onScopeOpened(final SenderContext<?> context) {
48+
49+
}
50+
51+
@Override
52+
public void onScopeClosed(final SenderContext<?> context) {
53+
54+
}
55+
56+
@Override
57+
public void onStop(final SenderContext<?> context) {
58+
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
org.apache.skywalking.apm.toolkit.micrometer.observation.SkywalkingContextSnapshotThreadLocalAccessor

0 commit comments

Comments
 (0)