Skip to content

Conversation

mmorel-35
Copy link
Contributor

@mmorel-35 mmorel-35 commented Aug 12, 2025

Description

Enable and fixes more rules from go-critic:

@mmorel-35 mmorel-35 force-pushed the gocritic/exposedSyncMutex branch from 3af20f8 to 50e4fb7 Compare August 12, 2025 20:45
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

❌ Patch coverage is 80.48780% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.4%. Comparing base (72e8b77) to head (2cf8caa).

Files with missing lines Patch % Lines
propagators/aws/xray/idgenerator.go 50.0% 4 Missing ⚠️
samplers/jaegerremote/sampler_remote.go 60.0% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #7726     +/-   ##
=======================================
- Coverage   78.4%   78.4%   -0.1%     
=======================================
  Files        184     184             
  Lines      14648   14656      +8     
=======================================
  Hits       11496   11496             
- Misses      2801    2809      +8     
  Partials     351     351             
Files with missing lines Coverage Δ
....mongodb.org/mongo-driver/mongo/otelmongo/mongo.go 90.0% <100.0%> (ø)
...ngodb.org/mongo-driver/v2/mongo/otelmongo/mongo.go 88.5% <100.0%> (ø)
samplers/jaegerremote/sampler.go 91.6% <100.0%> (ø)
zpages/spanprocessor.go 100.0% <100.0%> (ø)
propagators/aws/xray/idgenerator.go 88.5% <50.0%> (-11.5%) ⬇️
samplers/jaegerremote/sampler_remote.go 87.1% <60.0%> (-2.3%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mmorel-35 mmorel-35 marked this pull request as ready for review August 12, 2025 21:01
@mmorel-35 mmorel-35 requested review from a team and dashpole as code owners August 12, 2025 21:01
@flc1125 flc1125 added the Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG label Aug 13, 2025
@mmorel-35 mmorel-35 force-pushed the gocritic/exposedSyncMutex branch from 50e4fb7 to faa709c Compare August 13, 2025 04:58
@mmorel-35 mmorel-35 force-pushed the gocritic/exposedSyncMutex branch from faa709c to 08a5d60 Compare August 13, 2025 05:02
Copy link
Member

@flc1125 flc1125 left a comment

Choose a reason for hiding this comment

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

Overall, it's very good, with an experimental version section (for reference only), pending decision.

@mmorel-35 mmorel-35 force-pushed the gocritic/exposedSyncMutex branch from 08a5d60 to c624511 Compare August 13, 2025 05:15
pellared
pellared previously approved these changes Aug 14, 2025
Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Can you please add deperecation entries in the changelog?

@flc1125 flc1125 removed the Skip Changelog Allow PR to succeed without requiring an addition to the CHANGELOG label Aug 14, 2025
@mmorel-35 mmorel-35 force-pushed the gocritic/exposedSyncMutex branch 3 times, most recently from bbb6b0b to 823a26f Compare August 14, 2025 11:51
@pellared pellared dismissed their stale review August 18, 2025 08:10

stable modules should have the methods implemented as no-op

@mmorel-35 mmorel-35 force-pushed the gocritic/exposedSyncMutex branch from 3590ed9 to ecbf459 Compare August 18, 2025 08:59
mmorel-35 and others added 3 commits August 25, 2025 18:17
Signed-off-by: Matthieu MOREL <[email protected]>
Signed-off-by: Matthieu MOREL <[email protected]>
@mmorel-35 mmorel-35 force-pushed the gocritic/exposedSyncMutex branch from ecbf459 to 2238e3b Compare August 25, 2025 16:18
@pellared
Copy link
Member

Please notice https://github.com/open-telemetry/opentelemetry-go/blob/main/CONTRIBUTING.md#how-to-send-pull-requests:

Avoid rebasing and force-pushing to your branch to facilitate reviewing the pull request. Rewriting Git history makes it difficult to keep track of iterations during code review. All pull requests are squashed to a single commit upon merge to main.

@pellared pellared requested a review from MrAlias August 26, 2025 12:49
// IDGenerator is used for generating a new traceID and spanID.
type IDGenerator struct {
sync.Mutex
mu sync.Mutex
Copy link
Member

Choose a reason for hiding this comment

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

The field needs to be kept as removing an exported field is a breaking change.
The field should be marked as deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aren't the lign added between L28 and L47 here to handle deprecation ?

Copy link
Member

Choose a reason for hiding this comment

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

closed int64 // 0 - not closed, 1 - closed

sync.RWMutex // used to serialize access to samplerConfig.sampler
mu sync.RWMutex // used to serialize access to samplerConfig.sampler
Copy link
Member

Choose a reason for hiding this comment

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

The field needs to be kept as removing an exported field is a breaking change.
The field should be marked as deprecated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aren't the lign added between L98 and L117 here to handle deprecation ?

Copy link
Member

@pellared pellared Sep 9, 2025

Choose a reason for hiding this comment

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

This only handles deprecation of the "embedded methods".
But after making this field not embedded this would no longer compile:

package main

import "go.opentelemetry.io/contrib/samplers/jaegerremote"

func main() {
	s := new(jaegerremote.Sampler)
	s.RWMutex.Lock()
}

Thus this is a breaking change from Go perspective.
More: open-telemetry/opentelemetry-go#6274

Deprecate direct usage of mutex objects and introduce methods for locking/unlocking. Mark mutex fields as deprecated for specific samplers and propagators.
Deprecate direct exposure of mutex objects and suggest methods for locking/unlocking.
Added a deprecated mutex field to perOperationSampler struct.
Add a comment indicating ongoing deletion of the perOperationSampler mutex.
Comment on lines +75 to +76
sync.RWMutex // Deprecated: mutex is internal and shall not be used.
mu sync.RWMutex // used to serialize access to samplerConfig.sampler
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
sync.RWMutex // Deprecated: mutex is internal and shall not be used.
mu sync.RWMutex // used to serialize access to samplerConfig.sampler
sync.RWMutex // Deprecated: mutex is internal and shall not be used.

Comment on lines +22 to +23
sync.Mutex // Deprecated: mutex is internal and shall not be used.
mu sync.Mutex
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason for duplicating the fields?

Suggested change
sync.Mutex // Deprecated: mutex is internal and shall not be used.
mu sync.Mutex
sync.Mutex // Deprecated: mutex is internal and shall not be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wanted to fix exposedSyncMutex... this is a nightmare 😭. Please take it from here. I don’t want to here about this egg or chicken problem!

https://go-critic.com/overview.html#exposedsyncmutex

Copy link
Member

Choose a reason for hiding this comment

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

Cannot you add a //nolint that this is required for backwards compatibility?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants