Skip to content

Conversation

giortzisg
Copy link
Contributor

@giortzisg giortzisg commented Jul 2, 2025

Closes both #1048 and #1049.

Description

Adds tests for the logger to identify race conditions and fix everything uncovered.

Changes include:

  • Add locks when using SetAttributes to guard for panics.
  • Lock scope when trying to access propagation context on log.

@giortzisg giortzisg requested a review from cleptric July 2, 2025 10:50
@giortzisg giortzisg self-assigned this Jul 2, 2025
@giortzisg giortzisg added the Bug Issue type label Jul 2, 2025
Copy link

codecov bot commented Jul 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.08%. Comparing base (17421c4) to head (0a2c20d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1050      +/-   ##
==========================================
+ Coverage   86.88%   87.08%   +0.20%     
==========================================
  Files          55       55              
  Lines        5956     5971      +15     
==========================================
+ Hits         5175     5200      +25     
+ Misses        638      630       -8     
+ Partials      143      141       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@lcian
Copy link
Member

lcian commented Jul 7, 2025

There seem to be some more places where both the hub and scope are used without using the new function which could possibly still lead to race conditions, as an example:

  • gin/sentrygin.go in the handle function
  • fiber/sentryfiber.go in the handle function
  • dynamic_sampling_context.go
    etc.

I would suggest reviewing all usages of hub.Client() and hub.Scope() and checking whether they need to be corrected.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@cleptric cleptric marked this pull request as draft July 21, 2025 13:30
@giortzisg giortzisg force-pushed the fix-hub-race branch 4 times, most recently from da78b31 to 1065b95 Compare August 5, 2025 10:01
@giortzisg giortzisg marked this pull request as ready for review August 5, 2025 10:12
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@lcian lcian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, please see the comments

@giortzisg
Copy link
Contributor Author

@lcian For the cursor comment about nil scope. If you clone the Hub and scope should never be empty. We can still guard with nil checks on the scope.Set methods, but it should be ok as is right now also.

@lcian
Copy link
Member

lcian commented Aug 7, 2025

@lcian For the cursor comment about nil scope. If you clone the Hub and scope should never be empty. We can still guard with nil checks on the scope.Set methods, but it should be ok as is right now also.

Yep I see. I was talking about this one: #1050 (comment)
Screenshot 2025-08-07 at 11 38 55

cursor[bot]

This comment was marked as outdated.

hub_test.go Outdated
@@ -553,3 +555,19 @@ func TestHub_FlushWithContext(t *testing.T) {
t.Fatalf("expected message to be %v, got %v", wantEvent.Message, gotEvents[0].Message)
}
}

func TestHubEmptyClientShouldBeSafe(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean? 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That the hub shouldn't panic with an empty client 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we use a a test name with proper grammar then?

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@giortzisg giortzisg changed the title Fix race conditions on hub and span Fix race conditions on log when accessing scope Aug 12, 2025
@cleptric cleptric merged commit a100bf5 into master Aug 12, 2025
18 checks passed
@cleptric cleptric deleted the fix-hub-race branch August 12, 2025 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issue type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants