diff --git a/CHANGELOG.md b/CHANGELOG.md index 88fbeb3820..4495100edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +### Features + +- Make `RequestDetailsResolver` public ([#4326](https://github.com/getsentry/sentry-java/pull/4326)) + - `RequestDetailsResolver` is now public and has an additional constructor, making it easier to use a custom `TransportFactory` + ## 8.10.0 ### Features @@ -9,7 +16,7 @@ - Set `-Dio.opentelemetry.context.contextStorageProvider=io.sentry.opentelemetry.SentryContextStorageProvider` on your `java` command - Sentry will then wrap the other `ContextStorageProvider` that has been configured by loading it through SPI - If no other `ContextStorageProvider` is available or there are problems loading it, we fall back to using `SentryOtelThreadLocalStorage` - + ### Fixes - Update profile chunk rate limit and client report ([#4353](https://github.com/getsentry/sentry-java/pull/4353)) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 80da9a7430..78b5b0be2b 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -2185,6 +2185,12 @@ public final class io/sentry/RequestDetails { public fun getUrl ()Ljava/net/URL; } +public final class io/sentry/RequestDetailsResolver { + public fun (Lio/sentry/SentryOptions;)V + public fun (Ljava/lang/String;Ljava/lang/String;)V + public fun resolve ()Lio/sentry/RequestDetails; +} + public final class io/sentry/SamplingContext { public fun (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;)V public fun (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;Ljava/lang/Double;Ljava/util/Map;)V diff --git a/sentry/src/main/java/io/sentry/RequestDetailsResolver.java b/sentry/src/main/java/io/sentry/RequestDetailsResolver.java index bba4dc19ac..97dfc8318b 100644 --- a/sentry/src/main/java/io/sentry/RequestDetailsResolver.java +++ b/sentry/src/main/java/io/sentry/RequestDetailsResolver.java @@ -4,24 +4,39 @@ import java.net.URI; import java.util.HashMap; import java.util.Map; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** Resolves {@link RequestDetails}. */ -final class RequestDetailsResolver { +@ApiStatus.Experimental +public final class RequestDetailsResolver { /** HTTP Header for the user agent. */ private static final String USER_AGENT = "User-Agent"; /** HTTP Header for the authentication to Sentry. */ private static final String SENTRY_AUTH = "X-Sentry-Auth"; - private final @NotNull SentryOptions options; + private final @NotNull Dsn dsn; + private final @Nullable String sentryClientName; + public RequestDetailsResolver( + final @NotNull String dsn, final @Nullable String sentryClientName) { + Objects.requireNonNull(dsn, "dsn is required"); + + this.dsn = new Dsn(dsn); + this.sentryClientName = sentryClientName; + } + + @ApiStatus.Internal public RequestDetailsResolver(final @NotNull SentryOptions options) { - this.options = Objects.requireNonNull(options, "options is required"); + Objects.requireNonNull(options, "options is required"); + + this.dsn = options.retrieveParsedDsn(); + this.sentryClientName = options.getSentryClientName(); } @NotNull - RequestDetails resolve() { - final Dsn dsn = options.retrieveParsedDsn(); + public RequestDetails resolve() { final URI sentryUri = dsn.getSentryUri(); final String envelopeUrl = sentryUri.resolve(sentryUri.getPath() + "/envelope/").toString(); @@ -33,15 +48,14 @@ RequestDetails resolve() { + SentryClient.SENTRY_PROTOCOL_VERSION + "," + "sentry_client=" - + options.getSentryClientName() + + sentryClientName + "," + "sentry_key=" + publicKey + (secretKey != null && secretKey.length() > 0 ? (",sentry_secret=" + secretKey) : ""); - final String userAgent = options.getSentryClientName(); final Map headers = new HashMap<>(); - headers.put(USER_AGENT, userAgent); + headers.put(USER_AGENT, sentryClientName); headers.put(SENTRY_AUTH, authHeader); return new RequestDetails(envelopeUrl, headers);