-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrument DefaultSpan.create to return a bridged span. (#947)
- Loading branch information
Anuraag Agrawal
authored
Aug 12, 2020
1 parent
e268014
commit e9d456d
Showing
3 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...va/io/opentelemetry/auto/instrumentation/opentelemetryapi/DefaultSpanInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.auto.instrumentation.opentelemetryapi; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.isPublic; | ||
import static net.bytebuddy.matcher.ElementMatchers.isStatic; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
import com.google.auto.service.AutoService; | ||
import io.opentelemetry.auto.instrumentation.opentelemetryapi.trace.Bridging; | ||
import io.opentelemetry.auto.tooling.Instrumenter; | ||
import io.opentelemetry.trace.DefaultSpan; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
@AutoService(Instrumenter.class) | ||
public class DefaultSpanInstrumentation extends AbstractInstrumentation { | ||
@Override | ||
public ElementMatcher<? super TypeDescription> typeMatcher() { | ||
return named("unshaded.io.opentelemetry.trace.DefaultSpan"); | ||
} | ||
|
||
@Override | ||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() { | ||
return Collections.singletonMap( | ||
isMethod().and(isPublic()).and(isStatic()).and(named("create")), | ||
DefaultSpanInstrumentation.class.getName() + "$CreateAdvice"); | ||
} | ||
|
||
public static class CreateAdvice { | ||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void methodExit( | ||
@Advice.Return(readOnly = false) unshaded.io.opentelemetry.trace.Span span) { | ||
span = Bridging.toUnshaded(DefaultSpan.create(Bridging.toShaded(span.getContext()))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters