-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from grafana/fix/extension-sdk-interference
Fix interference between extension and Pyroscope SDK
- Loading branch information
Showing
5 changed files
with
129 additions
and
23 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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pyroscope_version=0.13.0 | ||
pyroscope_version=0.16.0 | ||
otel_profiling_version=0.10.3 |
71 changes: 71 additions & 0 deletions
71
src/main/java/io/otel/pyroscope/OtelProfilerSdkBridge.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,71 @@ | ||
package io.otel.pyroscope; | ||
|
||
import io.pyroscope.javaagent.api.ProfilerApi; | ||
import io.pyroscope.javaagent.api.ProfilerScopedContext; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
|
||
public class OtelProfilerSdkBridge implements ProfilerApi { | ||
|
||
private final Object sdkInstance; | ||
|
||
public OtelProfilerSdkBridge(Object sdkInstance) { | ||
this.sdkInstance = sdkInstance; | ||
} | ||
|
||
@Override | ||
public void startProfiling() { | ||
try { | ||
Method method = sdkInstance.getClass().getDeclaredMethod("startProfiling"); | ||
method.invoke(sdkInstance); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isProfilingStarted() { | ||
try { | ||
Method method = sdkInstance.getClass().getDeclaredMethod("isProfilingStarted"); | ||
return (boolean) method.invoke(sdkInstance); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public ProfilerScopedContext createScopedContext(Map<String, String> labels) { | ||
try { | ||
Method method = sdkInstance.getClass().getDeclaredMethod("createScopedContext", Map.class); | ||
Object ctx = method.invoke(sdkInstance, labels); | ||
|
||
return new ProfilerScopedContext() { | ||
|
||
@Override | ||
public void forEachLabel(BiConsumer<String, String> biConsumer) { | ||
try { | ||
Method forEachLabelMethod = ctx.getClass().getDeclaredMethod("forEachLabel", BiConsumer.class); | ||
forEachLabelMethod.invoke(ctx, biConsumer); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try { | ||
Method closeMethod = ctx.getClass().getDeclaredMethod("close"); | ||
closeMethod.invoke(ctx); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}; | ||
|
||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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
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