-
Notifications
You must be signed in to change notification settings - Fork 1k
spring-cloud-gateway support for spring boot 4 #15540
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
Open
jaydeluca
wants to merge
9
commits into
open-telemetry:main
Choose a base branch
from
jaydeluca:spring-cloud-update
base: main
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.
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f9189a9
spring boot 4 compatibility
jaydeluca 77393fc
Merge branch 'main' of github.com:jaydeluca/opentelemetry-java-instru…
jaydeluca 56cfa76
split out module
jaydeluca c03e214
consolidate
jaydeluca 7e72214
fossa and change minimum version
jaydeluca d9d24bd
fix package
jaydeluca 1cfd3b9
code review updates
jaydeluca 5bf09b1
fix tests
jaydeluca 0c0e37f
add nullaway to new module
jaydeluca 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
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
8 changes: 8 additions & 0 deletions
8
...tation/spring/spring-cloud-gateway/spring-cloud-gateway-common/javaagent/build.gradle.kts
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,8 @@ | ||
| plugins { | ||
| id("otel.javaagent-instrumentation") | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly("io.opentelemetry:opentelemetry-api") | ||
| compileOnly("io.opentelemetry:opentelemetry-api-incubator") | ||
| } | ||
80 changes: 80 additions & 0 deletions
80
.../io/opentelemetry/javaagent/instrumentation/spring/gateway/common/GatewayRouteHelper.java
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,80 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.javaagent.instrumentation.spring.gateway.common; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; | ||
| import java.util.regex.Pattern; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Shared helper class for Spring Cloud Gateway instrumentation across different versions (WebFlux | ||
| * and WebMVC). | ||
| */ | ||
| public final class GatewayRouteHelper { | ||
|
|
||
| /** Route ID attribute key. */ | ||
| public static final AttributeKey<String> ROUTE_ID_ATTRIBUTE = | ||
| AttributeKey.stringKey("spring-cloud-gateway.route.id"); | ||
|
|
||
| /** Route URI attribute key. */ | ||
| public static final AttributeKey<String> ROUTE_URI_ATTRIBUTE = | ||
| AttributeKey.stringKey("spring-cloud-gateway.route.uri"); | ||
|
|
||
| /** Route order attribute key. */ | ||
| public static final AttributeKey<Long> ROUTE_ORDER_ATTRIBUTE = | ||
| AttributeKey.longKey("spring-cloud-gateway.route.order"); | ||
|
|
||
| /** Route filter size attribute key. */ | ||
| public static final AttributeKey<Long> ROUTE_FILTER_SIZE_ATTRIBUTE = | ||
| AttributeKey.longKey("spring-cloud-gateway.route.filter.size"); | ||
|
|
||
| private static final boolean CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES; | ||
|
|
||
| static { | ||
| CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES = | ||
| AgentInstrumentationConfig.get() | ||
| .getBoolean( | ||
| "otel.instrumentation.spring-cloud-gateway.experimental-span-attributes", false); | ||
| } | ||
|
|
||
| /* Regex for UUID */ | ||
| private static final Pattern UUID_REGEX = | ||
| Pattern.compile( | ||
| "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); | ||
|
|
||
| private static final String INVALID_RANDOM_ROUTE_ID = | ||
| "org.springframework.util.AlternativeJdkIdGenerator@"; | ||
|
|
||
| private GatewayRouteHelper() {} | ||
|
|
||
| /** Returns whether experimental span attributes should be captured. */ | ||
| public static boolean shouldCaptureExperimentalSpanAttributes() { | ||
| return CAPTURE_EXPERIMENTAL_SPAN_ATTRIBUTES; | ||
| } | ||
|
|
||
| /** | ||
| * To avoid high cardinality, we ignore random UUID generated by Spring Cloud Gateway. Spring | ||
| * Cloud Gateway generates invalid random routeID, and it is fixed until 3.1.x | ||
| * | ||
| * @see <a | ||
| * href="https://github.com/spring-cloud/spring-cloud-gateway/commit/5002fe2e0a2825ef47dd667cade37b844c276cf6">Spring | ||
| * Cloud Gateway commit</a> | ||
| */ | ||
| @Nullable | ||
| public static String convergeRouteId(@Nullable String routeId) { | ||
| if (routeId == null || routeId.isEmpty()) { | ||
| return null; | ||
| } | ||
| if (UUID_REGEX.matcher(routeId).matches()) { | ||
| return null; | ||
| } | ||
| if (routeId.startsWith(INVALID_RANDOM_ROUTE_ID)) { | ||
| return null; | ||
| } | ||
| return routeId; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
aren't these already available through
otel.javaagent-instrumentation?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.
yes thank you