-
Notifications
You must be signed in to change notification settings - Fork 624
feat: otel javaagent #1189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tamassoltesz
wants to merge
20
commits into
11.1
Choose a base branch
from
feat/otel_javaagent
base: 11.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: otel javaagent #1189
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8fd4935
feat: add java cli options for javaagent and jmx
tamassoltesz 61477b5
fix: gitignore changes to allow resources jars
tamassoltesz 583fd76
feat: add otel javaagent jars
tamassoltesz 68f2de4
fix: loading agent from the agent dir
tamassoltesz d91318d
fix: changelog and build version
tamassoltesz 29ec494
fix: proper agent attach command on unix-like systems
tamassoltesz c206103
feat: aspect for wrapping methods in otel span
tamassoltesz e4be070
fix: add exception records to spans
tamassoltesz f050dab
fix: use javaagent's otel if present
tamassoltesz a5609d0
fix: fixing agent loading at startup
tamassoltesz 315ea7b
fix: add logging for the command that's being run
tamassoltesz 0bf21f7
fix: pinpoint runner image version
tamassoltesz 6a36676
fix: pinpoint runner image version
tamassoltesz 55e5df0
fix: tell the core branch name for the workflow
tamassoltesz 38c2b80
fix: build docker image with the right branches
tamassoltesz 73fd8b6
fix: publish-dev-docker formatting
tamassoltesz 31a546f
fix: using an other variable for deciding the current branch name
tamassoltesz 2eae4fb
fix: using an other variable for deciding the current branch name
tamassoltesz 966ef53
fix: update cli dependencies to make it the same version as core
tamassoltesz 9d6821c
fix: update implementationDependencies.json with aspectjrt
tamassoltesz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
/* | ||
* Copyright (c) 2025, VRAI Labs and/or its affiliates. All rights reserved. | ||
* | ||
* This software is licensed under the Apache License, Version 2.0 (the | ||
* "License") as published by the Apache Software Foundation. | ||
* | ||
* 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.supertokens.telemetry; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.context.Scope; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Aspect | ||
public class MethodSpanner { | ||
|
||
@Around("execution(* (@io.supertokens.pluginInterface.opentelemetry.WithinOtelSpan *).*(..))") | ||
public Object anyMethodInClassAnnotatedWithWithinOtelSpan(ProceedingJoinPoint joinPoint) throws Throwable { | ||
return withinOtelSpan(joinPoint); | ||
} | ||
|
||
@Around("execution(@io.supertokens.pluginInterface.opentelemetry.WithinOtelSpan * *(..))") | ||
public Object withinOtelSpan(ProceedingJoinPoint joinPoint) throws Throwable { | ||
Span span = GlobalOpenTelemetry.get().getTracer("core-tracer").spanBuilder(joinPoint.getSignature().getName()).startSpan(); | ||
try (Scope spanScope = span.makeCurrent()) { | ||
Map<String, String> methodArguments = new HashMap<>(); | ||
for (Object argument : joinPoint.getArgs()) { | ||
methodArguments.put(argument.getClass().getCanonicalName(), String.valueOf(argument)); | ||
} | ||
span.setAttribute("method.arguments", methodArguments.keySet().stream().map(key -> key + ": " + methodArguments.get(key)) | ||
.collect(Collectors.joining(", ", "{", "}"))); | ||
|
||
Object result = joinPoint.proceed(); //run the actual method | ||
|
||
if (result != null) { | ||
span.setAttribute("method.returnType", result.getClass().getCanonicalName()); | ||
span.setAttribute("method.returnValue", String.valueOf(result)); | ||
} else { | ||
span.setAttribute("method.returnType", "void"); | ||
} | ||
return result; | ||
} finally { | ||
span.end(); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code as written could throw a
NullPointerException
if any argument injoinPoint.getArgs()
is null. Consider adding null checks before accessingargument.getClass()
:This ensures the code handles null arguments gracefully while still capturing all method parameters for telemetry.
Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.