From ba772763b588b243e453f40282bba218c26547f7 Mon Sep 17 00:00:00 2001 From: ilya morgenshtern Date: Thu, 23 Nov 2023 21:00:38 +0200 Subject: [PATCH] make sampler without pointer --- .github/workflows/go-ossf-slsa3-publish.yml | 33 --------------------- .github/workflows/publish.yml | 30 ------------------- sampler/coralogix-sampler.go | 20 ++++++------- 3 files changed, 10 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/go-ossf-slsa3-publish.yml delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/go-ossf-slsa3-publish.yml b/.github/workflows/go-ossf-slsa3-publish.yml deleted file mode 100644 index 78f7678..0000000 --- a/.github/workflows/go-ossf-slsa3-publish.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Go Release Workflow - -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - "v*.*.*" # Push events to matching v*, i.e. v1.0, v20.15.10 - -jobs: - release: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - run: git fetch --force --tags - - uses: actions/setup-go@v4 - with: - go-version: '1.17' # The Go version to download (if necessary) and use. - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 - with: - distribution: goreleaser - version: latest - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: GO list - run: GOPROXY=proxy.golang.org go list -m github.com/adharshmk96/semver@${{ github.ref_name }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 820d378..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: publish - -on: - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' # e.g., v1.2.3 - workflow_dispatch: - inputs: - version: - description: 'Semantic Version (e.g., v1.2.3)' - required: true - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Determine Version - run: | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV - else - echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV - fi - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Run tests - run: GOPROXY=proxy.golang.org go list -m github.com/coralogix/coralogix-opentelemetry-go@${{ env.VERSION }} - diff --git a/sampler/coralogix-sampler.go b/sampler/coralogix-sampler.go index 2cca05a..a3665a1 100644 --- a/sampler/coralogix-sampler.go +++ b/sampler/coralogix-sampler.go @@ -14,29 +14,29 @@ const ( DistributedTransactionIdentifierTraceState = "cgx_transaction_distributed" ) -type CoralogixSampler struct { +type coralogixSampler struct { adaptedSampler traceSdk.Sampler } -func NewCoralogixSampler(adaptedSampler traceSdk.Sampler) *CoralogixSampler { +func NewCoralogixSampler(adaptedSampler traceSdk.Sampler) coralogixSampler { if adaptedSampler == nil { panic("sampler is null") } - return &CoralogixSampler{ + return coralogixSampler{ adaptedSampler: adaptedSampler, } } -func (s *CoralogixSampler) Description() string { +func (s coralogixSampler) Description() string { return "coralogix-sampler" } -func (s *CoralogixSampler) ShouldSample(parameters traceSdk.SamplingParameters) traceSdk.SamplingResult { +func (s coralogixSampler) ShouldSample(parameters traceSdk.SamplingParameters) traceSdk.SamplingResult { adaptedSamplingResult := s.adaptedSampler.ShouldSample(parameters) return s.generateTransactionSamplingResult(parameters.ParentContext, parameters.Name, adaptedSamplingResult) } -func (s *CoralogixSampler) generateTransactionSamplingResult(ctx context.Context, name string, adaptedSamplingResult traceSdk.SamplingResult) traceSdk.SamplingResult { +func (s coralogixSampler) generateTransactionSamplingResult(ctx context.Context, name string, adaptedSamplingResult traceSdk.SamplingResult) traceSdk.SamplingResult { newTracingState := s.generateNewTraceState(ctx, name, adaptedSamplingResult) newAttributes := s.injectAttributes(adaptedSamplingResult, newTracingState) return traceSdk.SamplingResult{ @@ -46,7 +46,7 @@ func (s *CoralogixSampler) generateTransactionSamplingResult(ctx context.Context } } -func (s *CoralogixSampler) injectAttributes(adaptedSamplingResult traceSdk.SamplingResult, newTracingState traceCore.TraceState) []attribute.KeyValue { +func (s coralogixSampler) injectAttributes(adaptedSamplingResult traceSdk.SamplingResult, newTracingState traceCore.TraceState) []attribute.KeyValue { sampledAttributes := adaptedSamplingResult.Attributes transactionIdentifier := attribute.String(TransactionIdentifier, newTracingState.Get(TransactionIdentifierTraceState)) @@ -55,11 +55,11 @@ func (s *CoralogixSampler) injectAttributes(adaptedSamplingResult traceSdk.Sampl return append(sampledAttributes, transactionIdentifier, distributedTransactionIdentifier) } -func (s *CoralogixSampler) getDescription() string { +func (s *coralogixSampler) getDescription() string { return "coralogix-sampler" } -func (s *CoralogixSampler) generateNewTraceState(ctx context.Context, name string, samplingResult traceSdk.SamplingResult) traceCore.TraceState { +func (s *coralogixSampler) generateNewTraceState(ctx context.Context, name string, samplingResult traceSdk.SamplingResult) traceCore.TraceState { parentSpanContext := s.getParentSpanContext(ctx) parentTraceState := samplingResult.Tracestate @@ -81,7 +81,7 @@ func (s *CoralogixSampler) generateNewTraceState(ctx context.Context, name strin return parentTraceState } -func (s *CoralogixSampler) getParentSpanContext(ctx context.Context) traceCore.SpanContext { +func (s *coralogixSampler) getParentSpanContext(ctx context.Context) traceCore.SpanContext { span := traceCore.SpanFromContext(ctx) if span != nil { return span.SpanContext()