Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import rx.Observable;
Expand Down Expand Up @@ -46,53 +47,57 @@ public void transform(TypeTransformer transformer) {
public static class CouchbaseClientAdvice {

@Advice.OnMethodEnter
public static void trackCallDepth(@Advice.Local("otelCallDepth") CallDepth callDepth) {
callDepth = CallDepth.forClass(CouchbaseCluster.class);
public static CallDepth trackCallDepth() {
CallDepth callDepth = CallDepth.forClass(CouchbaseCluster.class);
callDepth.getAndIncrement();
return callDepth;
}

@AssignReturned.ToReturned
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void subscribeResult(
public static Observable<?> subscribeResult(
@Advice.Origin("#t") Class<?> declaringClass,
@Advice.Origin("#m") String methodName,
@Advice.FieldValue("bucket") String bucket,
@Advice.Return(readOnly = false) Observable<?> result,
@Advice.Local("otelCallDepth") CallDepth callDepth) {
@Advice.Return Observable<?> result,
@Advice.Enter CallDepth callDepth) {
if (callDepth.decrementAndGet() > 0) {
return;
return result;
}
CouchbaseRequestInfo request =
CouchbaseRequestInfo.create(bucket, declaringClass, methodName);
result = Observable.create(new TracedOnSubscribe<>(result, instrumenter(), request));
return Observable.create(new TracedOnSubscribe<>(result, instrumenter(), request));
}
}

@SuppressWarnings("unused")
public static class CouchbaseClientQueryAdvice {

@Advice.OnMethodEnter
public static void trackCallDepth(@Advice.Local("otelCallDepth") CallDepth callDepth) {
callDepth = CallDepth.forClass(CouchbaseCluster.class);
public static CallDepth trackCallDepth() {
CallDepth callDepth = CallDepth.forClass(CouchbaseCluster.class);
callDepth.getAndIncrement();
return callDepth;
}

@AssignReturned.ToReturned
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void subscribeResult(
public static Observable<?> subscribeResult(
@Advice.Origin("#t") Class<?> declaringClass,
@Advice.Origin("#m") String methodName,
@Advice.FieldValue("bucket") String bucket,
@Advice.Argument(value = 0, optional = true) Object query,
@Advice.Return(readOnly = false) Observable<?> result,
@Advice.Local("otelCallDepth") CallDepth callDepth) {
@Advice.Return Observable<?> result,
@Advice.Enter CallDepth callDepth) {
if (callDepth.decrementAndGet() > 0) {
return;
return result;
}

CouchbaseRequestInfo request =
query == null
? CouchbaseRequestInfo.create(bucket, declaringClass, methodName)
: CouchbaseRequestInfo.create(bucket, query);
result = Observable.create(new TracedOnSubscribe<>(result, instrumenter(), request));
return Observable.create(new TracedOnSubscribe<>(result, instrumenter(), request));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.asm.Advice.AssignReturned;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import rx.Observable;
Expand All @@ -43,23 +44,25 @@ public void transform(TypeTransformer transformer) {
public static class CouchbaseClientAdvice {

@Advice.OnMethodEnter
public static void trackCallDepth(@Advice.Local("otelCallDepth") CallDepth callDepth) {
callDepth = CallDepth.forClass(CouchbaseCluster.class);
public static CallDepth trackCallDepth() {
CallDepth callDepth = CallDepth.forClass(CouchbaseCluster.class);
callDepth.getAndIncrement();
return callDepth;
}

@AssignReturned.ToReturned
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void subscribeResult(
public static Observable<?> subscribeResult(
@Advice.Origin("#t") Class<?> declaringClass,
@Advice.Origin("#m") String methodName,
@Advice.Return(readOnly = false) Observable<?> result,
@Advice.Local("otelCallDepth") CallDepth callDepth) {
@Advice.Return Observable<?> result,
@Advice.Enter CallDepth callDepth) {
if (callDepth.decrementAndGet() > 0) {
return;
return result;
}

CouchbaseRequestInfo request = CouchbaseRequestInfo.create(null, declaringClass, methodName);
result = Observable.create(new TracedOnSubscribe<>(result, instrumenter(), request));
return Observable.create(new TracedOnSubscribe<>(result, instrumenter(), request));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public String getModuleGroup() {
public List<String> injectedClassNames() {
return singletonList("rx.OpenTelemetryTracingUtil");
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

package io.opentelemetry.javaagent.instrumentation.couchbase.v2_6;

import static io.opentelemetry.javaagent.instrumentation.couchbase.v2_6.VirtualFieldHelper.COUCHBASE_REQUEST_INFO;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import com.couchbase.client.core.message.CouchbaseRequest;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
Expand Down Expand Up @@ -43,9 +43,7 @@ public static class CouchbaseCoreAdvice {

@Advice.OnMethodEnter(suppress = Throwable.class)
public static void addOperationIdToSpan(@Advice.Argument(0) CouchbaseRequest request) {
VirtualField<CouchbaseRequest, CouchbaseRequestInfo> virtualField =
VirtualField.find(CouchbaseRequest.class, CouchbaseRequestInfo.class);
CouchbaseRequestInfo requestInfo = virtualField.get(request);
CouchbaseRequestInfo requestInfo = COUCHBASE_REQUEST_INFO.get(request);
if (requestInfo != null) {
return;
}
Expand All @@ -55,7 +53,7 @@ public static void addOperationIdToSpan(@Advice.Argument(0) CouchbaseRequest req
if (requestInfo != null) {
// The scope from the initial rxJava subscribe is not available to the networking layer
// To transfer the request info it is added to the context store
virtualField.set(request, requestInfo);
COUCHBASE_REQUEST_INFO.set(request, requestInfo);

requestInfo.setOperationId(request.operationId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
public String getModuleGroup() {
return "couchbase";
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

package io.opentelemetry.javaagent.instrumentation.couchbase.v2_6;

import static io.opentelemetry.javaagent.instrumentation.couchbase.v2_6.VirtualFieldHelper.COUCHBASE_REQUEST_INFO;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import com.couchbase.client.core.message.CouchbaseRequest;
import com.couchbase.client.deps.io.netty.channel.ChannelHandlerContext;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import io.opentelemetry.javaagent.instrumentation.couchbase.v2_0.CouchbaseRequestInfo;
Expand Down Expand Up @@ -51,10 +51,7 @@ public static void addNetworkTagsToSpan(
@Advice.Argument(0) ChannelHandlerContext channelHandlerContext,
@Advice.Argument(1) CouchbaseRequest request) {

VirtualField<CouchbaseRequest, CouchbaseRequestInfo> virtualField =
VirtualField.find(CouchbaseRequest.class, CouchbaseRequestInfo.class);

CouchbaseRequestInfo requestInfo = virtualField.get(request);
CouchbaseRequestInfo requestInfo = COUCHBASE_REQUEST_INFO.get(request);
if (requestInfo != null) {
requestInfo.setPeerAddress(channelHandlerContext.channel().remoteAddress());
requestInfo.setLocalAddress(localSocket);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.couchbase.v2_6;

import com.couchbase.client.core.message.CouchbaseRequest;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import io.opentelemetry.javaagent.instrumentation.couchbase.v2_0.CouchbaseRequestInfo;

public class VirtualFieldHelper {
public static final VirtualField<CouchbaseRequest, CouchbaseRequestInfo> COUCHBASE_REQUEST_INFO =
VirtualField.find(CouchbaseRequest.class, CouchbaseRequestInfo.class);

private VirtualFieldHelper() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
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.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.Collections;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class CouchbaseInstrumentationModule extends InstrumentationModule {
public class CouchbaseInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public CouchbaseInstrumentationModule() {
super("couchbase", "couchbase-3.1.6");
}
Expand All @@ -32,4 +34,9 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
public List<TypeInstrumentation> typeInstrumentations() {
return Collections.singletonList(new CouchbaseEnvironmentInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
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.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.Collections;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class CouchbaseInstrumentationModule extends InstrumentationModule {
public class CouchbaseInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public CouchbaseInstrumentationModule() {
super("couchbase", "couchbase-3.1");
}
Expand All @@ -32,4 +34,9 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
public List<TypeInstrumentation> typeInstrumentations() {
return Collections.singletonList(new CouchbaseEnvironmentInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
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.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.Collections;
import java.util.List;
import net.bytebuddy.matcher.ElementMatcher;

@AutoService(InstrumentationModule.class)
public class CouchbaseInstrumentationModule extends InstrumentationModule {
public class CouchbaseInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {
public CouchbaseInstrumentationModule() {
super("couchbase", "couchbase-3.2");
}
Expand All @@ -30,4 +32,9 @@ public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
public List<TypeInstrumentation> typeInstrumentations() {
return Collections.singletonList(new CouchbaseEnvironmentInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}