Skip to content

Commit 58e9007

Browse files
milanboerslcian
andauthored
Make RequestDetailsResolver public (#4326)
* Make RequestDetailsResolver public * changelog * correct changelog --------- Co-authored-by: Lorenzo Cian <[email protected]> Co-authored-by: Lorenzo Cian <[email protected]>
1 parent 468a479 commit 58e9007

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Features
6+
7+
- Make `RequestDetailsResolver` public ([#4326](https://github.com/getsentry/sentry-java/pull/4326))
8+
- `RequestDetailsResolver` is now public and has an additional constructor, making it easier to use a custom `TransportFactory`
9+
310
## 8.10.0
411

512
### Features
@@ -9,7 +16,7 @@
916
- Set `-Dio.opentelemetry.context.contextStorageProvider=io.sentry.opentelemetry.SentryContextStorageProvider` on your `java` command
1017
- Sentry will then wrap the other `ContextStorageProvider` that has been configured by loading it through SPI
1118
- If no other `ContextStorageProvider` is available or there are problems loading it, we fall back to using `SentryOtelThreadLocalStorage`
12-
19+
1320
### Fixes
1421

1522
- Update profile chunk rate limit and client report ([#4353](https://github.com/getsentry/sentry-java/pull/4353))

sentry/api/sentry.api

+6
Original file line numberDiff line numberDiff line change
@@ -2185,6 +2185,12 @@ public final class io/sentry/RequestDetails {
21852185
public fun getUrl ()Ljava/net/URL;
21862186
}
21872187

2188+
public final class io/sentry/RequestDetailsResolver {
2189+
public fun <init> (Lio/sentry/SentryOptions;)V
2190+
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
2191+
public fun resolve ()Lio/sentry/RequestDetails;
2192+
}
2193+
21882194
public final class io/sentry/SamplingContext {
21892195
public fun <init> (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;)V
21902196
public fun <init> (Lio/sentry/TransactionContext;Lio/sentry/CustomSamplingContext;Ljava/lang/Double;Ljava/util/Map;)V

sentry/src/main/java/io/sentry/RequestDetailsResolver.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,39 @@
44
import java.net.URI;
55
import java.util.HashMap;
66
import java.util.Map;
7+
import org.jetbrains.annotations.ApiStatus;
78
import org.jetbrains.annotations.NotNull;
9+
import org.jetbrains.annotations.Nullable;
810

911
/** Resolves {@link RequestDetails}. */
10-
final class RequestDetailsResolver {
12+
@ApiStatus.Experimental
13+
public final class RequestDetailsResolver {
1114
/** HTTP Header for the user agent. */
1215
private static final String USER_AGENT = "User-Agent";
1316
/** HTTP Header for the authentication to Sentry. */
1417
private static final String SENTRY_AUTH = "X-Sentry-Auth";
1518

16-
private final @NotNull SentryOptions options;
19+
private final @NotNull Dsn dsn;
20+
private final @Nullable String sentryClientName;
1721

22+
public RequestDetailsResolver(
23+
final @NotNull String dsn, final @Nullable String sentryClientName) {
24+
Objects.requireNonNull(dsn, "dsn is required");
25+
26+
this.dsn = new Dsn(dsn);
27+
this.sentryClientName = sentryClientName;
28+
}
29+
30+
@ApiStatus.Internal
1831
public RequestDetailsResolver(final @NotNull SentryOptions options) {
19-
this.options = Objects.requireNonNull(options, "options is required");
32+
Objects.requireNonNull(options, "options is required");
33+
34+
this.dsn = options.retrieveParsedDsn();
35+
this.sentryClientName = options.getSentryClientName();
2036
}
2137

2238
@NotNull
23-
RequestDetails resolve() {
24-
final Dsn dsn = options.retrieveParsedDsn();
39+
public RequestDetails resolve() {
2540
final URI sentryUri = dsn.getSentryUri();
2641
final String envelopeUrl = sentryUri.resolve(sentryUri.getPath() + "/envelope/").toString();
2742

@@ -33,15 +48,14 @@ RequestDetails resolve() {
3348
+ SentryClient.SENTRY_PROTOCOL_VERSION
3449
+ ","
3550
+ "sentry_client="
36-
+ options.getSentryClientName()
51+
+ sentryClientName
3752
+ ","
3853
+ "sentry_key="
3954
+ publicKey
4055
+ (secretKey != null && secretKey.length() > 0 ? (",sentry_secret=" + secretKey) : "");
41-
final String userAgent = options.getSentryClientName();
4256

4357
final Map<String, String> headers = new HashMap<>();
44-
headers.put(USER_AGENT, userAgent);
58+
headers.put(USER_AGENT, sentryClientName);
4559
headers.put(SENTRY_AUTH, authHeader);
4660

4761
return new RequestDetails(envelopeUrl, headers);

0 commit comments

Comments
 (0)