Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- 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`
- Make `RequestDetailsResolver` public ([#4326](https://github.com/getsentry/sentry-java/pull/4326))

Check failure on line 12 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / danger / danger

The changelog entry seems to be part of an already released section `## 8.10.0`. Consider moving the entry to the `## Unreleased` section, please.
- `RequestDetailsResolver` is now public and has an additional constructor, making it easier to use a custom `TransportFactory`

### Fixes

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) {
Comment thread
lcian marked this conversation as resolved.
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