-
-
Notifications
You must be signed in to change notification settings - Fork 465
Also use port when checking if a request is made to Sentry DSN #4231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f951e32
Also use port when checking if a request is made to Sentry DSN
adinauer 47602d2
changelog
adinauer 66c7023
Merge branch 'main' into feat/consider-port-for-is-internal-span-check
adinauer e518122
Merge branch 'main' into feat/consider-port-for-is-internal-span-check
adinauer 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
251 changes: 251 additions & 0 deletions
251
...ntelemetry/sentry-opentelemetry-core/src/test/kotlin/OtelInternalSpanDetectionUtilTest.kt
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,251 @@ | ||
| package io.sentry.opentelemetry | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey | ||
| import io.opentelemetry.api.trace.SpanKind | ||
| import io.opentelemetry.sdk.internal.AttributesMap | ||
| import io.opentelemetry.semconv.HttpAttributes | ||
| import io.opentelemetry.semconv.SemanticAttributes | ||
| import io.opentelemetry.semconv.ServerAttributes | ||
| import io.opentelemetry.semconv.UrlAttributes | ||
| import io.sentry.IScopes | ||
| import io.sentry.SentryOptions | ||
| import org.mockito.kotlin.mock | ||
| import org.mockito.kotlin.whenever | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertTrue | ||
|
|
||
| class OtelInternalSpanDetectionUtilTest { | ||
|
|
||
| private class Fixture { | ||
| val scopes = mock<IScopes>() | ||
| val attributes = AttributesMap.create(100, 100) | ||
| val options = SentryOptions.empty() | ||
| var spanKind: SpanKind = SpanKind.INTERNAL | ||
|
|
||
| init { | ||
| whenever(scopes.options).thenReturn(options) | ||
| } | ||
| } | ||
|
|
||
| private val fixture = Fixture() | ||
|
|
||
| @Test | ||
| fun `detects split url as internal (span kind client)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.CLIENT) | ||
| givenAttributes( | ||
| mapOf( | ||
| HttpAttributes.HTTP_REQUEST_METHOD to "GET", | ||
| UrlAttributes.URL_SCHEME to "https", | ||
| UrlAttributes.URL_PATH to "/path/to/123", | ||
| UrlAttributes.URL_QUERY to "q=123456&b=X", | ||
| ServerAttributes.SERVER_ADDRESS to "io.sentry", | ||
| ServerAttributes.SERVER_PORT to 8081L | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `detects full url as internal (span kind client)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.CLIENT) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "https://io.sentry:8081" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `detects deprecated url as internal (span kind client)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.CLIENT) | ||
| givenAttributes( | ||
| mapOf( | ||
| SemanticAttributes.HTTP_URL to "https://io.sentry:8081" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `detects split url as internal (span kind internal)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.INTERNAL) | ||
| givenAttributes( | ||
| mapOf( | ||
| HttpAttributes.HTTP_REQUEST_METHOD to "GET", | ||
| UrlAttributes.URL_SCHEME to "https", | ||
| UrlAttributes.URL_PATH to "/path/to/123", | ||
| UrlAttributes.URL_QUERY to "q=123456&b=X", | ||
| ServerAttributes.SERVER_ADDRESS to "io.sentry", | ||
| ServerAttributes.SERVER_PORT to 8081L | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `detects full url as internal (span kind internal)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.INTERNAL) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "https://io.sentry:8081" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `detects deprecated url as internal (span kind internal)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.INTERNAL) | ||
| givenAttributes( | ||
| mapOf( | ||
| SemanticAttributes.HTTP_URL to "https://io.sentry:8081" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `does not detect full url as internal (span kind server)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.SERVER) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "https://io.sentry:8081" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsNotConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `does not detect full url as internal (span kind producer)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.PRODUCER) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "https://io.sentry:8081" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsNotConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `does not detect full url as internal (span kind consumer)`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpanKind(SpanKind.CONSUMER) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "https://io.sentry:8081" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsNotConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `detects full spotlight url as internal`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpotlightEnabled(true) | ||
| givenSpanKind(SpanKind.CLIENT) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "http://localhost:8969/stream" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `detects full spotlight url as internal with custom spotlight url`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpotlightEnabled(true) | ||
| givenSpotlightUrl("http://localhost:8090/stream") | ||
| givenSpanKind(SpanKind.CLIENT) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "http://localhost:8090/stream" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `does not detect mismatching full spotlight url as internal`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpotlightEnabled(true) | ||
| givenSpanKind(SpanKind.CLIENT) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "http://localhost:8080/stream" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsNotConsideredInternal() | ||
| } | ||
|
|
||
| @Test | ||
| fun `does not detect mismatching full customized spotlight url as internal`() { | ||
| givenDsn("https://publicKey:secretKey@io.sentry:8081/path/id?sample.rate=0.1") | ||
| givenSpotlightEnabled(true) | ||
| givenSpotlightUrl("http://localhost:8090/stream") | ||
| givenSpanKind(SpanKind.CLIENT) | ||
| givenAttributes( | ||
| mapOf( | ||
| UrlAttributes.URL_FULL to "http://localhost:8091/stream" | ||
| ) | ||
| ) | ||
|
|
||
| thenRequestIsNotConsideredInternal() | ||
| } | ||
|
|
||
| private fun givenAttributes(map: Map<AttributeKey<out Any>, Any>) { | ||
| map.forEach { k, v -> | ||
| fixture.attributes.put(k, v) | ||
| } | ||
| } | ||
|
|
||
| private fun givenDsn(dsn: String) { | ||
| fixture.options.dsn = dsn | ||
| } | ||
|
|
||
| private fun givenSpotlightEnabled(enabled: Boolean) { | ||
| fixture.options.isEnableSpotlight = enabled | ||
| } | ||
|
|
||
| private fun givenSpotlightUrl(url: String) { | ||
| fixture.options.spotlightConnectionUrl = url | ||
| } | ||
|
|
||
| private fun givenSpanKind(spanKind: SpanKind) { | ||
| fixture.spanKind = spanKind | ||
| } | ||
|
|
||
| private fun thenRequestIsConsideredInternal() { | ||
| assertTrue(checkIfInternal()) | ||
| } | ||
|
|
||
| private fun thenRequestIsNotConsideredInternal() { | ||
| assertFalse(checkIfInternal()) | ||
| } | ||
|
|
||
| private fun checkIfInternal(): Boolean { | ||
| return OtelInternalSpanDetectionUtil.isSentryRequest(fixture.scopes, fixture.spanKind, fixture.attributes) | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.