Skip to content

Make RequestDetailsResolver public #4326

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 4 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,12 @@ public final class io/sentry/RequestDetails {
public fun getUrl ()Ljava/net/URL;
}

public final class io/sentry/RequestDetailsResolver {
public fun <init> (Lio/sentry/SentryOptions;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public fun resolve ()Lio/sentry/RequestDetails;
}

public final class io/sentry/SamplingContext {
public fun <init> (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;)V
public fun <init> (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;Ljava/lang/Double;Ljava/util/Map;)V
Expand Down
30 changes: 22 additions & 8 deletions sentry/src/main/java/io/sentry/RequestDetailsResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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<String, String> headers = new HashMap<>();
headers.put(USER_AGENT, userAgent);
headers.put(USER_AGENT, sentryClientName);
headers.put(SENTRY_AUTH, authHeader);

return new RequestDetails(envelopeUrl, headers);
Expand Down
Loading