- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 460
Hubs / Scopes Merge 16 - Move client and throwable to span map to scope #3318
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
          
          
            20 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      305baf5
              
                replace hub with scopes
              
              
                adinauer 95f5e1b
              
                Add Scopes
              
              
                adinauer 27f2398
              
                Introduce `IScopes` interface.
              
              
                adinauer ce3c14f
              
                Replace `IHub` with `IScopes` in core
              
              
                adinauer ce615f4
              
                Replace `IHub` with `IScopes` in android core
              
              
                adinauer 22ddc00
              
                Replace `IHub` with `IScopes` in android integrations
              
              
                adinauer 305c217
              
                Replace `IHub` with `IScopes` in apollo integrations
              
              
                adinauer da927bc
              
                Replace `IHub` with `IScopes` in okhttp integration
              
              
                adinauer 8279276
              
                Replace `IHub` with `IScopes` in graphql integration
              
              
                adinauer 9bfc086
              
                Replace `IHub` with `IScopes` in logging integrations
              
              
                adinauer b998e50
              
                Replace `IHub` with `IScopes` in more integrations
              
              
                adinauer 739827a
              
                Replace `IHub` with `IScopes` in OTel integration
              
              
                adinauer 69f2d63
              
                Replace `IHub` with `IScopes` in Spring 5 / Spring Boot 2 integrations
              
              
                adinauer 792d482
              
                Replace `IHub` with `IScopes` in Spring 6 / Spring Boot 3 integrations
              
              
                adinauer 9bcbce6
              
                Replace `IHub` with `IScopes` in samples
              
              
                adinauer 3f25a4b
              
                Merge branch 'feat/hsm-13-replacements-in-samples' into feat/hubs-sco…
              
              
                adinauer d6fb40a
              
                gitscopes -> github
              
              
                adinauer 7752bcc
              
                Replace ThreadLocal with ScopesStorage
              
              
                adinauer 1e329c5
              
                Move client and throwable to span map to scope
              
              
                adinauer eeac7f3
              
                Merge branch '8.x.x' into feat/hsm-16-move-client-span-map
              
              
                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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
|  | @@ -9,19 +9,15 @@ | |
| import io.sentry.protocol.SentryTransaction; | ||
| import io.sentry.protocol.User; | ||
| import io.sentry.transport.RateLimiter; | ||
| import io.sentry.util.ExceptionUtils; | ||
| import io.sentry.util.HintUtils; | ||
| import io.sentry.util.Objects; | ||
| import io.sentry.util.Pair; | ||
| import io.sentry.util.TracingUtils; | ||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.lang.ref.WeakReference; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.WeakHashMap; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
|  | @@ -40,10 +36,6 @@ public final class Scopes implements IScopes, MetricsApi.IMetricsInterface { | |
| private final @NotNull SentryOptions options; | ||
| private volatile boolean isEnabled; | ||
| private final @NotNull TracesSampler tracesSampler; | ||
|  | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a separate map per  | ||
| // TODO should this go on global scope? | ||
| private final @NotNull Map<Throwable, Pair<WeakReference<ISpan>, String>> throwableToSpan = | ||
| Collections.synchronizedMap(new WeakHashMap<>()); | ||
| private final @NotNull TransactionPerformanceCollector transactionPerformanceCollector; | ||
| private final @NotNull MetricsApi metricsApi; | ||
|  | ||
|  | @@ -120,7 +112,10 @@ public boolean isAncestorOf(final @Nullable Scopes otherScopes) { | |
|  | ||
| // TODO add to IScopes interface | ||
| public @NotNull Scopes forkedCurrentScope(final @NotNull String creator) { | ||
| return new Scopes(scope.clone(), isolationScope, this, options, creator); | ||
| IScope clone = scope.clone(); | ||
| // TODO should use isolation scope | ||
| // return new Scopes(clone, isolationScope, this, options, creator); | ||
| return new Scopes(clone, clone, this, options, creator); | ||
| } | ||
|  | ||
| // // TODO in Sentry.init? | ||
|  | @@ -180,23 +175,7 @@ public boolean isEnabled() { | |
| } | ||
|  | ||
| private void assignTraceContext(final @NotNull SentryEvent event) { | ||
| if (options.isTracingEnabled() && event.getThrowable() != null) { | ||
| final Pair<WeakReference<ISpan>, String> pair = | ||
| throwableToSpan.get(ExceptionUtils.findRootCause(event.getThrowable())); | ||
| if (pair != null) { | ||
| final WeakReference<ISpan> spanWeakRef = pair.getFirst(); | ||
| if (event.getContexts().getTrace() == null && spanWeakRef != null) { | ||
| final ISpan span = spanWeakRef.get(); | ||
| if (span != null) { | ||
| event.getContexts().setTrace(span.getSpanContext()); | ||
| } | ||
| } | ||
| final String transactionName = pair.getSecond(); | ||
| if (event.getTransaction() == null && transactionName != null) { | ||
| event.setTransaction(transactionName); | ||
| } | ||
| } | ||
| } | ||
| Sentry.getGlobalScope().assignTraceContext(event); | ||
| } | ||
|  | ||
| private IScope buildLocalScope( | ||
|  | @@ -691,10 +670,10 @@ public void bindClient(final @NotNull ISentryClient client) { | |
| } else { | ||
| if (client != null) { | ||
| options.getLogger().log(SentryLevel.DEBUG, "New client bound to scope."); | ||
| getDefaultWriteScope().setClient(client); | ||
| getDefaultWriteScope().bindClient(client); | ||
| } else { | ||
| options.getLogger().log(SentryLevel.DEBUG, "NoOp client bound to scope."); | ||
| getDefaultWriteScope().setClient(NoOpSentryClient.getInstance()); | ||
| getDefaultWriteScope().bindClient(NoOpSentryClient.getInstance()); | ||
| } | ||
| } | ||
| } | ||
|  | @@ -871,34 +850,26 @@ public void setSpanContext( | |
| final @NotNull Throwable throwable, | ||
| final @NotNull ISpan span, | ||
| final @NotNull String transactionName) { | ||
| Objects.requireNonNull(throwable, "throwable is required"); | ||
| Objects.requireNonNull(span, "span is required"); | ||
| Objects.requireNonNull(transactionName, "transactionName is required"); | ||
| // to match any cause, span context is always attached to the root cause of the exception | ||
| final Throwable rootCause = ExceptionUtils.findRootCause(throwable); | ||
| // the most inner span should be assigned to a throwable | ||
| if (!throwableToSpan.containsKey(rootCause)) { | ||
| throwableToSpan.put(rootCause, new Pair<>(new WeakReference<>(span), transactionName)); | ||
| } | ||
| } | ||
|  | ||
| // TODO this seems unused | ||
| @Nullable | ||
| SpanContext getSpanContext(final @NotNull Throwable throwable) { | ||
| Objects.requireNonNull(throwable, "throwable is required"); | ||
| final Throwable rootCause = ExceptionUtils.findRootCause(throwable); | ||
| final Pair<WeakReference<ISpan>, String> pair = this.throwableToSpan.get(rootCause); | ||
| if (pair != null) { | ||
| final WeakReference<ISpan> spanWeakRef = pair.getFirst(); | ||
| if (spanWeakRef != null) { | ||
| final ISpan span = spanWeakRef.get(); | ||
| if (span != null) { | ||
| return span.getSpanContext(); | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| Sentry.getGlobalScope().setSpanContext(throwable, span, transactionName); | ||
| } | ||
|  | ||
| // // TODO this seems unused | ||
|         
                  adinauer marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| // @Nullable | ||
| // SpanContext getSpanContext(final @NotNull Throwable throwable) { | ||
| // Objects.requireNonNull(throwable, "throwable is required"); | ||
| // final Throwable rootCause = ExceptionUtils.findRootCause(throwable); | ||
| // final Pair<WeakReference<ISpan>, String> pair = this.throwableToSpan.get(rootCause); | ||
| // if (pair != null) { | ||
| // final WeakReference<ISpan> spanWeakRef = pair.getFirst(); | ||
| // if (spanWeakRef != null) { | ||
| // final ISpan span = spanWeakRef.get(); | ||
| // if (span != null) { | ||
| // return span.getSpanContext(); | ||
| // } | ||
| // } | ||
| // } | ||
| // return null; | ||
| // } | ||
|  | ||
| @Override | ||
| public @Nullable ISpan getSpan() { | ||
|  | ||
  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.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs testing once enough changes have been implemented to check for memory leaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, we might have to remove the entries that have been sent to
Sentryfrom the map.But this would have been an issue with
Hubas well I think.