2020-03-24 07:41:10 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2019-10-22 22:19:11 +02:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2020-11-04 19:10:58 +02:00
|
|
|
package trace // import "go.opentelemetry.io/otel/sdk/trace"
|
2019-10-22 22:19:11 +02:00
|
|
|
|
|
|
|
import (
|
2020-10-26 18:20:49 +02:00
|
|
|
"context"
|
2021-03-08 21:12:13 +02:00
|
|
|
"fmt"
|
2019-10-22 22:19:11 +02:00
|
|
|
"sync"
|
|
|
|
"sync/atomic"
|
|
|
|
|
2020-11-16 19:30:54 +02:00
|
|
|
"go.opentelemetry.io/otel"
|
2022-01-11 02:58:01 +02:00
|
|
|
"go.opentelemetry.io/otel/internal/global"
|
2020-06-09 20:47:54 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/instrumentation"
|
2020-03-13 22:07:36 +02:00
|
|
|
"go.opentelemetry.io/otel/sdk/resource"
|
2021-11-13 18:35:04 +02:00
|
|
|
"go.opentelemetry.io/otel/trace"
|
2023-10-19 19:16:24 +02:00
|
|
|
"go.opentelemetry.io/otel/trace/embedded"
|
|
|
|
"go.opentelemetry.io/otel/trace/noop"
|
2019-10-22 22:19:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2019-11-01 20:40:29 +02:00
|
|
|
defaultTracerName = "go.opentelemetry.io/otel/sdk/tracer"
|
2019-10-22 22:19:11 +02:00
|
|
|
)
|
|
|
|
|
2022-04-25 22:22:49 +02:00
|
|
|
// tracerProviderConfig.
|
2021-05-14 22:28:28 +02:00
|
|
|
type tracerProviderConfig struct {
|
|
|
|
// processors contains collection of SpanProcessors that are processing pipeline
|
|
|
|
// for spans in the trace signal.
|
|
|
|
// SpanProcessors registered with a TracerProvider and are called at the start
|
|
|
|
// and end of a Span's lifecycle, and are called in the order they are
|
|
|
|
// registered.
|
2020-09-09 19:19:03 +02:00
|
|
|
processors []SpanProcessor
|
2021-03-18 19:48:13 +02:00
|
|
|
|
|
|
|
// sampler is the default sampler used when creating new spans.
|
|
|
|
sampler Sampler
|
|
|
|
|
|
|
|
// idGenerator is used to generate all Span and Trace IDs when needed.
|
|
|
|
idGenerator IDGenerator
|
|
|
|
|
|
|
|
// spanLimits defines the attribute, event, and link limits for spans.
|
|
|
|
spanLimits SpanLimits
|
|
|
|
|
|
|
|
// resource contains attributes representing an entity that produces telemetry.
|
|
|
|
resource *resource.Resource
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2024-01-19 16:18:16 +02:00
|
|
|
// MarshalLog is the marshaling function used by the logging system to represent this Provider.
|
2022-01-11 02:58:01 +02:00
|
|
|
func (cfg tracerProviderConfig) MarshalLog() interface{} {
|
|
|
|
return struct {
|
|
|
|
SpanProcessors []SpanProcessor
|
|
|
|
SamplerType string
|
|
|
|
IDGeneratorType string
|
|
|
|
SpanLimits SpanLimits
|
|
|
|
Resource *resource.Resource
|
|
|
|
}{
|
|
|
|
SpanProcessors: cfg.processors,
|
|
|
|
SamplerType: fmt.Sprintf("%T", cfg.sampler),
|
|
|
|
IDGeneratorType: fmt.Sprintf("%T", cfg.idGenerator),
|
|
|
|
SpanLimits: cfg.spanLimits,
|
|
|
|
Resource: cfg.resource,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-19 22:15:07 +02:00
|
|
|
// TracerProvider is an OpenTelemetry TracerProvider. It provides Tracers to
|
|
|
|
// instrumentation so it can trace operational flow through a system.
|
2020-09-24 00:16:13 +02:00
|
|
|
type TracerProvider struct {
|
2023-10-19 19:16:24 +02:00
|
|
|
embedded.TracerProvider
|
|
|
|
|
2019-10-22 22:19:11 +02:00
|
|
|
mu sync.Mutex
|
2022-07-06 20:55:46 +02:00
|
|
|
namedTracer map[instrumentation.Scope]*tracer
|
2023-03-27 18:38:47 +02:00
|
|
|
spanProcessors atomic.Pointer[spanProcessorStates]
|
2023-03-28 02:05:44 +02:00
|
|
|
|
|
|
|
isShutdown atomic.Bool
|
2022-02-02 01:20:35 +02:00
|
|
|
|
|
|
|
// These fields are not protected by the lock mu. They are assumed to be
|
|
|
|
// immutable after creation of the TracerProvider.
|
|
|
|
sampler Sampler
|
|
|
|
idGenerator IDGenerator
|
|
|
|
spanLimits SpanLimits
|
|
|
|
resource *resource.Resource
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2020-11-07 00:13:31 +02:00
|
|
|
var _ trace.TracerProvider = &TracerProvider{}
|
2019-10-22 22:19:11 +02:00
|
|
|
|
2021-03-18 18:34:47 +02:00
|
|
|
// NewTracerProvider returns a new and configured TracerProvider.
|
|
|
|
//
|
|
|
|
// By default the returned TracerProvider is configured with:
|
2022-08-25 04:42:28 +02:00
|
|
|
// - a ParentBased(AlwaysSample) Sampler
|
|
|
|
// - a random number IDGenerator
|
|
|
|
// - the resource.Default() Resource
|
|
|
|
// - the default SpanLimits.
|
2021-03-18 18:34:47 +02:00
|
|
|
//
|
|
|
|
// The passed opts are used to override these default values and configure the
|
|
|
|
// returned TracerProvider appropriately.
|
2020-09-24 00:16:13 +02:00
|
|
|
func NewTracerProvider(opts ...TracerProviderOption) *TracerProvider {
|
2022-03-03 17:56:07 +02:00
|
|
|
o := tracerProviderConfig{
|
|
|
|
spanLimits: NewSpanLimits(),
|
|
|
|
}
|
Allow setting the Sampler via environment variables (#2517)
* Allow setting the Sampler via environment variables (#2305)
* Add changelog entry.
* Replace t.Setenv with internaltest/SetEnvVariables for Go <= 1.6.
* Handle the lack of a sampler argument without logging errors.
* Add additional test cases and error checks.
* Refactor documentation.
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
* emitBatchOverhead should only be used for splitting spans into batches (#2512)
* emitBatchOverhead should only be used for splitting spans into batches (#2503)
* limit max packet size parameter
* Add additional errors types, simplify abstractions and error handling
* Make error comparisons less fragile.
* Fix typo in jaeger example (#2524)
* Fix some typos in docs for Go libraries (#2520)
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Fix getting-started.md Run function (#2527)
* Fix getting-started.md Run function, it assigns this new context to a variable shared between connections in to accept loop. Thus creating a growing chain of contexts. so every calculate fibonacci request, all spans in a trace.
* add a comment explaining the reason for that new variable
* update example fib
* Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 across the project (#2545)
* update go-cmp to 0.5.7
* fixes go.sums
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
* Un-escape url coding when parsing baggage. (#2529)
* un-escape url coding when parsing baggage.
* Added changelog
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Bump go.opentelemetry.io/proto/otlp from 0.11.0 to 0.12.0 (#2546)
* Update go.opentelemetry.io/proto/otlp to v0.12.0
* Changelog
* Update CHANGELOG.md
Fix's md linting
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Remove unused sdk/internal/santize (#2549)
* Add links to code examples and docs (#2551)
* Bump github.com/prometheus/client_golang from 1.11.0 to 1.12.0 in /exporters/prometheus (#2541)
* Bump github.com/prometheus/client_golang in /exporters/prometheus
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.11.0...v1.12.0)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* go mod tidy
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Optimize evictedQueue implementation and use (#2556)
* Optimize evictedQueue impl and use
Avoid unnecessary allocations in the recordingSpan by using an
evictedQueue type instead of a pointer to one.
Lazy allocate the evictedQueue queue to prevent unnecessary operations
for spans without any use of the queue.
Document the evictedQueue
* Fix grammar
* Add env support for batch span processor (#2515)
* Add env support for batch span processor
* Update changelog
* lint
* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools (#2566)
* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.1.8 to 0.1.9.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.1.8...v0.1.9)
---
updated-dependencies:
- dependency-name: golang.org/x/tools
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump github.com/golangci/golangci-lint from 1.43.0 to 1.44.0 in /internal/tools (#2567)
* Bump github.com/golangci/golangci-lint in /internal/tools
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump github.com/prometheus/client_golang from 1.12.0 to 1.12.1 in /exporters/prometheus (#2570)
* Bump github.com/prometheus/client_golang in /exporters/prometheus
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.12.0 to 1.12.1.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.12.0...v1.12.1)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Fix TestBackoffRetry in otlp/internal/retry package (#2562)
* Fix TestBackoffRetry in otlp retry pkg
The delay of the retry is within two times a randomization factor (the
back-off time is delay * random number within [1 - factor, 1 + factor].
This means the waitFunc in TestBackoffRetry needs to check the delay is
within an appropriate delta, not equal to configure initial delay.
* Fix delta value
* Fix delta
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlptrace (#2568)
* Bump google.golang.org/grpc in /exporters/otlp/otlptrace
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /example/otel-collector (#2565)
* Bump google.golang.org/grpc in /example/otel-collector
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlpmetric (#2572)
* Bump google.golang.org/grpc in /exporters/otlp/otlpmetric
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Change Options to accept type not pointer (#2558)
* Change trace options to accept type not pointer
Add benchmark to show allocation improvement.
* Update CONTRIBUTING.md guidelines
* Update all Option iface
* Fix grammar in CONTRIBUTING
* Do not store TracerProvider or Tracer fields in SDK recordingSpan (#2575)
* Do not store TracerProvider fields in span
Instead of keeping a reference to the span's Tracer, and therefore also
it's TracerProvider, and the associated resource and spanLimits just
keep the reference to the Tracer. Refer to the TracerProvider fields
when needed instead.
* Make span refer to the inst lib via the Tracer
Instead of holding a field in the span, refer to the field in the parent
Tracer.
* [website_docs] fix page meta-links (#2580)
Contributes to https://github.com/open-telemetry/opentelemetry.io/issues/1096
/cc @cartermp @austinlparker
* Validate members once, in `NewMember` (#2522)
* use NewMember, or specify if the member is not validated when creating new ones
* expect members to already be validated when creating a new package
* add changelog entry
* add an isEmpty field to member and property for quick validation
* rename isEmpty to hasData
So by default, an empty struct really is marked as having no data
* Update baggage/baggage_test.go
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* don't validate the member in parseMember, we alredy ran that validation
We also don't want to use NewMember, as that runs the property
validation again, making the benchmark quite slower
* move changelog entry to the fixed section
* provide the member/property data when returning an invalid error
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* Fix link to Zipkin exporter (#2581)
Currently it is linked to the old package that was moved.
* Unexport EnvBatchSpanProcessor* constants (#2583)
* Move BSP env support to internal
* Use pkg name
* Update env test
* Use internal/env in sdk/trace
* Avoid an extra allocation in applyTracerProviderEnvConfigs.
* Add additional errors for ratio > 1.0.
* Add test cases for ratio > 1.0.
* Update CHANGELOG.md
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
Co-authored-by: jaychung <ken8203@gmail.com>
Co-authored-by: Ben Wells <b.v.wells@gmail.com>
Co-authored-by: Jeremy Kaplan <jeremy@stytch.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: thinkgo <49174849+thinkgos@users.noreply.github.com>
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Chao Weng <19381524+sincejune@users.noreply.github.com>
Co-authored-by: Patrice Chalin <chalin@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2022-03-21 18:39:30 +02:00
|
|
|
o = applyTracerProviderEnvConfigs(o)
|
2019-10-22 22:19:11 +02:00
|
|
|
|
|
|
|
for _, opt := range opts {
|
2022-02-01 23:51:23 +02:00
|
|
|
o = opt.apply(o)
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2022-02-01 23:51:23 +02:00
|
|
|
o = ensureValidTracerProviderConfig(o)
|
2021-03-18 19:48:13 +02:00
|
|
|
|
2020-09-24 00:16:13 +02:00
|
|
|
tp := &TracerProvider{
|
2022-07-06 20:55:46 +02:00
|
|
|
namedTracer: make(map[instrumentation.Scope]*tracer),
|
2021-03-18 19:48:13 +02:00
|
|
|
sampler: o.sampler,
|
|
|
|
idGenerator: o.idGenerator,
|
|
|
|
spanLimits: o.spanLimits,
|
|
|
|
resource: o.resource,
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
2022-01-11 02:58:01 +02:00
|
|
|
global.Info("TracerProvider created", "config", o)
|
|
|
|
|
2023-04-01 16:57:35 +02:00
|
|
|
spss := make(spanProcessorStates, 0, len(o.processors))
|
2020-09-09 19:19:03 +02:00
|
|
|
for _, sp := range o.processors {
|
2022-10-12 22:44:18 +02:00
|
|
|
spss = append(spss, newSpanProcessorState(sp))
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
2023-03-27 18:38:47 +02:00
|
|
|
tp.spanProcessors.Store(&spss)
|
2019-10-22 22:19:11 +02:00
|
|
|
|
2020-09-09 19:19:03 +02:00
|
|
|
return tp
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2021-03-03 22:09:58 +02:00
|
|
|
// Tracer returns a Tracer with the given name and options. If a Tracer for
|
|
|
|
// the given name and options does not exist it is created, otherwise the
|
|
|
|
// existing Tracer is returned.
|
|
|
|
//
|
|
|
|
// If name is empty, DefaultTracerName is used instead.
|
|
|
|
//
|
|
|
|
// This method is safe to be called concurrently.
|
2020-11-07 00:13:31 +02:00
|
|
|
func (p *TracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
|
2023-03-28 02:05:44 +02:00
|
|
|
// This check happens before the mutex is acquired to avoid deadlocking if Tracer() is called from within Shutdown().
|
|
|
|
if p.isShutdown.Load() {
|
2023-10-19 19:16:24 +02:00
|
|
|
return noop.NewTracerProvider().Tracer(name, opts...)
|
2023-03-28 02:05:44 +02:00
|
|
|
}
|
2020-11-07 00:13:31 +02:00
|
|
|
c := trace.NewTracerConfig(opts...)
|
2019-10-22 22:19:11 +02:00
|
|
|
if name == "" {
|
|
|
|
name = defaultTracerName
|
|
|
|
}
|
2022-07-06 20:55:46 +02:00
|
|
|
is := instrumentation.Scope{
|
2022-09-09 16:06:58 +02:00
|
|
|
Name: name,
|
|
|
|
Version: c.InstrumentationVersion(),
|
|
|
|
SchemaURL: c.SchemaURL(),
|
2020-06-09 20:47:54 +02:00
|
|
|
}
|
2023-03-28 02:05:44 +02:00
|
|
|
|
|
|
|
t, ok := func() (trace.Tracer, bool) {
|
|
|
|
p.mu.Lock()
|
|
|
|
defer p.mu.Unlock()
|
|
|
|
// Must check the flag after acquiring the mutex to avoid returning a valid tracer if Shutdown() ran
|
|
|
|
// after the first check above but before we acquired the mutex.
|
|
|
|
if p.isShutdown.Load() {
|
2023-10-19 19:16:24 +02:00
|
|
|
return noop.NewTracerProvider().Tracer(name, opts...), true
|
2023-03-28 02:05:44 +02:00
|
|
|
}
|
|
|
|
t, ok := p.namedTracer[is]
|
|
|
|
if !ok {
|
|
|
|
t = &tracer{
|
|
|
|
provider: p,
|
|
|
|
instrumentationScope: is,
|
|
|
|
}
|
|
|
|
p.namedTracer[is] = t
|
2020-06-09 20:47:54 +02:00
|
|
|
}
|
2023-03-28 02:05:44 +02:00
|
|
|
return t, ok
|
|
|
|
}()
|
|
|
|
if !ok {
|
|
|
|
// This code is outside the mutex to not hold the lock while calling third party logging code:
|
|
|
|
// - That code may do slow things like I/O, which would prolong the duration the lock is held,
|
|
|
|
// slowing down all tracing consumers.
|
|
|
|
// - Logging code may be instrumented with tracing and deadlock because it could try
|
|
|
|
// acquiring the same non-reentrant mutex.
|
|
|
|
global.Info("Tracer created", "name", name, "version", is.Version, "schemaURL", is.SchemaURL)
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2022-04-25 22:22:49 +02:00
|
|
|
// RegisterSpanProcessor adds the given SpanProcessor to the list of SpanProcessors.
|
2022-10-12 22:44:18 +02:00
|
|
|
func (p *TracerProvider) RegisterSpanProcessor(sp SpanProcessor) {
|
2023-03-28 02:05:44 +02:00
|
|
|
// This check prevents calls during a shutdown.
|
|
|
|
if p.isShutdown.Load() {
|
|
|
|
return
|
|
|
|
}
|
2019-10-22 22:19:11 +02:00
|
|
|
p.mu.Lock()
|
|
|
|
defer p.mu.Unlock()
|
2023-03-28 02:05:44 +02:00
|
|
|
// This check prevents calls after a shutdown.
|
|
|
|
if p.isShutdown.Load() {
|
2023-01-03 19:51:56 +02:00
|
|
|
return
|
|
|
|
}
|
2023-04-01 16:57:35 +02:00
|
|
|
|
|
|
|
current := p.getSpanProcessors()
|
|
|
|
newSPS := make(spanProcessorStates, 0, len(current)+1)
|
|
|
|
newSPS = append(newSPS, current...)
|
2022-10-12 22:44:18 +02:00
|
|
|
newSPS = append(newSPS, newSpanProcessorState(sp))
|
2023-03-27 18:38:47 +02:00
|
|
|
p.spanProcessors.Store(&newSPS)
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2022-04-25 22:22:49 +02:00
|
|
|
// UnregisterSpanProcessor removes the given SpanProcessor from the list of SpanProcessors.
|
2022-10-12 22:44:18 +02:00
|
|
|
func (p *TracerProvider) UnregisterSpanProcessor(sp SpanProcessor) {
|
2023-03-28 02:05:44 +02:00
|
|
|
// This check prevents calls during a shutdown.
|
|
|
|
if p.isShutdown.Load() {
|
|
|
|
return
|
|
|
|
}
|
2020-08-22 09:38:52 +02:00
|
|
|
p.mu.Lock()
|
|
|
|
defer p.mu.Unlock()
|
2023-03-28 02:05:44 +02:00
|
|
|
// This check prevents calls after a shutdown.
|
|
|
|
if p.isShutdown.Load() {
|
2023-01-03 19:51:56 +02:00
|
|
|
return
|
|
|
|
}
|
2023-04-01 16:57:35 +02:00
|
|
|
old := p.getSpanProcessors()
|
2022-10-12 22:44:18 +02:00
|
|
|
if len(old) == 0 {
|
2020-09-24 20:43:23 +02:00
|
|
|
return
|
|
|
|
}
|
2023-04-01 16:57:35 +02:00
|
|
|
spss := make(spanProcessorStates, len(old))
|
|
|
|
copy(spss, old)
|
2020-09-24 20:43:23 +02:00
|
|
|
|
|
|
|
// stop the span processor if it is started and remove it from the list
|
|
|
|
var stopOnce *spanProcessorState
|
|
|
|
var idx int
|
2021-03-03 18:26:26 +02:00
|
|
|
for i, sps := range spss {
|
2022-10-12 22:44:18 +02:00
|
|
|
if sps.sp == sp {
|
2020-09-24 20:43:23 +02:00
|
|
|
stopOnce = sps
|
|
|
|
idx = i
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
}
|
2020-09-24 20:43:23 +02:00
|
|
|
if stopOnce != nil {
|
|
|
|
stopOnce.state.Do(func() {
|
2022-10-12 22:44:18 +02:00
|
|
|
if err := sp.Shutdown(context.Background()); err != nil {
|
2020-12-11 07:28:41 +02:00
|
|
|
otel.Handle(err)
|
|
|
|
}
|
2019-10-22 22:19:11 +02:00
|
|
|
})
|
|
|
|
}
|
2021-03-03 18:26:26 +02:00
|
|
|
if len(spss) > 1 {
|
|
|
|
copy(spss[idx:], spss[idx+1:])
|
2020-09-24 20:43:23 +02:00
|
|
|
}
|
2021-03-03 18:26:26 +02:00
|
|
|
spss[len(spss)-1] = nil
|
|
|
|
spss = spss[:len(spss)-1]
|
2020-09-24 20:43:23 +02:00
|
|
|
|
2023-03-27 18:38:47 +02:00
|
|
|
p.spanProcessors.Store(&spss)
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2021-03-08 21:12:13 +02:00
|
|
|
// ForceFlush immediately exports all spans that have not yet been exported for
|
|
|
|
// all the registered span processors.
|
|
|
|
func (p *TracerProvider) ForceFlush(ctx context.Context) error {
|
2023-04-01 16:57:35 +02:00
|
|
|
spss := p.getSpanProcessors()
|
2021-03-08 21:12:13 +02:00
|
|
|
if len(spss) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, sps := range spss {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := sps.sp.ForceFlush(ctx); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-03 19:51:56 +02:00
|
|
|
// Shutdown shuts down TracerProvider. All registered span processors are shut down
|
|
|
|
// in the order they were registered and any held computational resources are released.
|
2023-03-28 02:05:44 +02:00
|
|
|
// After Shutdown is called, all methods are no-ops.
|
2020-10-26 18:20:49 +02:00
|
|
|
func (p *TracerProvider) Shutdown(ctx context.Context) error {
|
2023-03-28 02:05:44 +02:00
|
|
|
// This check prevents deadlocks in case of recursive shutdown.
|
|
|
|
if p.isShutdown.Load() {
|
|
|
|
return nil
|
|
|
|
}
|
2023-01-03 19:51:56 +02:00
|
|
|
p.mu.Lock()
|
|
|
|
defer p.mu.Unlock()
|
2023-03-28 02:05:44 +02:00
|
|
|
// This check prevents calls after a shutdown has already been done concurrently.
|
|
|
|
if !p.isShutdown.CompareAndSwap(false, true) { // did toggle?
|
2023-03-22 18:47:42 +02:00
|
|
|
return nil
|
|
|
|
}
|
2023-01-03 19:51:56 +02:00
|
|
|
|
2022-09-02 18:50:44 +02:00
|
|
|
var retErr error
|
2023-04-01 16:57:35 +02:00
|
|
|
for _, sps := range p.getSpanProcessors() {
|
2021-03-08 21:12:13 +02:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return ctx.Err()
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
2020-10-26 18:20:49 +02:00
|
|
|
sps.state.Do(func() {
|
2021-03-08 21:12:13 +02:00
|
|
|
err = sps.sp.Shutdown(ctx)
|
2020-10-26 18:20:49 +02:00
|
|
|
})
|
2021-03-08 21:12:13 +02:00
|
|
|
if err != nil {
|
2022-09-02 18:50:44 +02:00
|
|
|
if retErr == nil {
|
|
|
|
retErr = err
|
|
|
|
} else {
|
|
|
|
// Poor man's list of errors
|
|
|
|
retErr = fmt.Errorf("%v; %v", retErr, err)
|
|
|
|
}
|
2021-03-08 21:12:13 +02:00
|
|
|
}
|
2020-10-26 18:20:49 +02:00
|
|
|
}
|
2023-03-27 18:38:47 +02:00
|
|
|
p.spanProcessors.Store(&spanProcessorStates{})
|
2022-09-02 18:50:44 +02:00
|
|
|
return retErr
|
2020-10-26 18:20:49 +02:00
|
|
|
}
|
|
|
|
|
2023-04-01 16:57:35 +02:00
|
|
|
func (p *TracerProvider) getSpanProcessors() spanProcessorStates {
|
|
|
|
return *(p.spanProcessors.Load())
|
|
|
|
}
|
|
|
|
|
2022-05-19 22:15:07 +02:00
|
|
|
// TracerProviderOption configures a TracerProvider.
|
2021-05-14 22:28:28 +02:00
|
|
|
type TracerProviderOption interface {
|
2022-02-01 23:51:23 +02:00
|
|
|
apply(tracerProviderConfig) tracerProviderConfig
|
2021-05-14 22:28:28 +02:00
|
|
|
}
|
|
|
|
|
2022-02-01 23:51:23 +02:00
|
|
|
type traceProviderOptionFunc func(tracerProviderConfig) tracerProviderConfig
|
2021-05-14 22:28:28 +02:00
|
|
|
|
2022-02-01 23:51:23 +02:00
|
|
|
func (fn traceProviderOptionFunc) apply(cfg tracerProviderConfig) tracerProviderConfig {
|
|
|
|
return fn(cfg)
|
2021-05-14 22:28:28 +02:00
|
|
|
}
|
|
|
|
|
2020-09-24 00:16:13 +02:00
|
|
|
// WithSyncer registers the exporter with the TracerProvider using a
|
2020-09-09 19:19:03 +02:00
|
|
|
// SimpleSpanProcessor.
|
2021-04-27 18:23:09 +02:00
|
|
|
//
|
|
|
|
// This is not recommended for production use. The synchronous nature of the
|
|
|
|
// SimpleSpanProcessor that will wrap the exporter make it good for testing,
|
|
|
|
// debugging, or showing examples of other feature, but it will be slow and
|
|
|
|
// have a high computation resource usage overhead. The WithBatcher option is
|
|
|
|
// recommended for production use instead.
|
2021-04-07 17:03:43 +02:00
|
|
|
func WithSyncer(e SpanExporter) TracerProviderOption {
|
2020-09-09 19:19:03 +02:00
|
|
|
return WithSpanProcessor(NewSimpleSpanProcessor(e))
|
|
|
|
}
|
|
|
|
|
2020-09-24 00:16:13 +02:00
|
|
|
// WithBatcher registers the exporter with the TracerProvider using a
|
2020-09-09 19:19:03 +02:00
|
|
|
// BatchSpanProcessor configured with the passed opts.
|
2021-04-07 17:03:43 +02:00
|
|
|
func WithBatcher(e SpanExporter, opts ...BatchSpanProcessorOption) TracerProviderOption {
|
2020-09-09 19:19:03 +02:00
|
|
|
return WithSpanProcessor(NewBatchSpanProcessor(e, opts...))
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2020-09-24 00:16:13 +02:00
|
|
|
// WithSpanProcessor registers the SpanProcessor with a TracerProvider.
|
|
|
|
func WithSpanProcessor(sp SpanProcessor) TracerProviderOption {
|
2022-02-01 23:51:23 +02:00
|
|
|
return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig {
|
2021-05-14 22:28:28 +02:00
|
|
|
cfg.processors = append(cfg.processors, sp)
|
2022-02-01 23:51:23 +02:00
|
|
|
return cfg
|
2021-05-14 22:28:28 +02:00
|
|
|
})
|
2019-10-22 22:19:11 +02:00
|
|
|
}
|
|
|
|
|
2021-03-18 18:34:47 +02:00
|
|
|
// WithResource returns a TracerProviderOption that will configure the
|
|
|
|
// Resource r as a TracerProvider's Resource. The configured Resource is
|
|
|
|
// referenced by all the Tracers the TracerProvider creates. It represents the
|
|
|
|
// entity producing telemetry.
|
|
|
|
//
|
|
|
|
// If this option is not used, the TracerProvider will use the
|
|
|
|
// resource.Default() Resource by default.
|
2020-09-24 00:16:13 +02:00
|
|
|
func WithResource(r *resource.Resource) TracerProviderOption {
|
2022-02-01 23:51:23 +02:00
|
|
|
return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig {
|
2021-06-08 18:46:42 +02:00
|
|
|
var err error
|
|
|
|
cfg.resource, err = resource.Merge(resource.Environment(), r)
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
}
|
2022-02-01 23:51:23 +02:00
|
|
|
return cfg
|
2021-05-14 22:28:28 +02:00
|
|
|
})
|
2020-03-13 22:07:36 +02:00
|
|
|
}
|
2020-12-10 03:30:32 +02:00
|
|
|
|
2021-03-18 18:34:47 +02:00
|
|
|
// WithIDGenerator returns a TracerProviderOption that will configure the
|
|
|
|
// IDGenerator g as a TracerProvider's IDGenerator. The configured IDGenerator
|
|
|
|
// is used by the Tracers the TracerProvider creates to generate new Span and
|
|
|
|
// Trace IDs.
|
|
|
|
//
|
|
|
|
// If this option is not used, the TracerProvider will use a random number
|
|
|
|
// IDGenerator by default.
|
2020-12-10 03:30:32 +02:00
|
|
|
func WithIDGenerator(g IDGenerator) TracerProviderOption {
|
2022-02-01 23:51:23 +02:00
|
|
|
return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig {
|
2021-03-18 19:48:13 +02:00
|
|
|
if g != nil {
|
2021-05-14 22:28:28 +02:00
|
|
|
cfg.idGenerator = g
|
2021-03-18 19:48:13 +02:00
|
|
|
}
|
2022-02-01 23:51:23 +02:00
|
|
|
return cfg
|
2021-05-14 22:28:28 +02:00
|
|
|
})
|
2020-12-10 03:30:32 +02:00
|
|
|
}
|
2021-03-08 23:43:11 +02:00
|
|
|
|
2021-03-18 18:34:47 +02:00
|
|
|
// WithSampler returns a TracerProviderOption that will configure the Sampler
|
|
|
|
// s as a TracerProvider's Sampler. The configured Sampler is used by the
|
|
|
|
// Tracers the TracerProvider creates to make their sampling decisions for the
|
|
|
|
// Spans they create.
|
|
|
|
//
|
Allow setting the Sampler via environment variables (#2517)
* Allow setting the Sampler via environment variables (#2305)
* Add changelog entry.
* Replace t.Setenv with internaltest/SetEnvVariables for Go <= 1.6.
* Handle the lack of a sampler argument without logging errors.
* Add additional test cases and error checks.
* Refactor documentation.
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
* emitBatchOverhead should only be used for splitting spans into batches (#2512)
* emitBatchOverhead should only be used for splitting spans into batches (#2503)
* limit max packet size parameter
* Add additional errors types, simplify abstractions and error handling
* Make error comparisons less fragile.
* Fix typo in jaeger example (#2524)
* Fix some typos in docs for Go libraries (#2520)
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Fix getting-started.md Run function (#2527)
* Fix getting-started.md Run function, it assigns this new context to a variable shared between connections in to accept loop. Thus creating a growing chain of contexts. so every calculate fibonacci request, all spans in a trace.
* add a comment explaining the reason for that new variable
* update example fib
* Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 across the project (#2545)
* update go-cmp to 0.5.7
* fixes go.sums
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
* Un-escape url coding when parsing baggage. (#2529)
* un-escape url coding when parsing baggage.
* Added changelog
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Bump go.opentelemetry.io/proto/otlp from 0.11.0 to 0.12.0 (#2546)
* Update go.opentelemetry.io/proto/otlp to v0.12.0
* Changelog
* Update CHANGELOG.md
Fix's md linting
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Remove unused sdk/internal/santize (#2549)
* Add links to code examples and docs (#2551)
* Bump github.com/prometheus/client_golang from 1.11.0 to 1.12.0 in /exporters/prometheus (#2541)
* Bump github.com/prometheus/client_golang in /exporters/prometheus
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.11.0...v1.12.0)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* go mod tidy
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Optimize evictedQueue implementation and use (#2556)
* Optimize evictedQueue impl and use
Avoid unnecessary allocations in the recordingSpan by using an
evictedQueue type instead of a pointer to one.
Lazy allocate the evictedQueue queue to prevent unnecessary operations
for spans without any use of the queue.
Document the evictedQueue
* Fix grammar
* Add env support for batch span processor (#2515)
* Add env support for batch span processor
* Update changelog
* lint
* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools (#2566)
* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.1.8 to 0.1.9.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.1.8...v0.1.9)
---
updated-dependencies:
- dependency-name: golang.org/x/tools
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump github.com/golangci/golangci-lint from 1.43.0 to 1.44.0 in /internal/tools (#2567)
* Bump github.com/golangci/golangci-lint in /internal/tools
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump github.com/prometheus/client_golang from 1.12.0 to 1.12.1 in /exporters/prometheus (#2570)
* Bump github.com/prometheus/client_golang in /exporters/prometheus
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.12.0 to 1.12.1.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.12.0...v1.12.1)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Fix TestBackoffRetry in otlp/internal/retry package (#2562)
* Fix TestBackoffRetry in otlp retry pkg
The delay of the retry is within two times a randomization factor (the
back-off time is delay * random number within [1 - factor, 1 + factor].
This means the waitFunc in TestBackoffRetry needs to check the delay is
within an appropriate delta, not equal to configure initial delay.
* Fix delta value
* Fix delta
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlptrace (#2568)
* Bump google.golang.org/grpc in /exporters/otlp/otlptrace
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /example/otel-collector (#2565)
* Bump google.golang.org/grpc in /example/otel-collector
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlpmetric (#2572)
* Bump google.golang.org/grpc in /exporters/otlp/otlpmetric
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Change Options to accept type not pointer (#2558)
* Change trace options to accept type not pointer
Add benchmark to show allocation improvement.
* Update CONTRIBUTING.md guidelines
* Update all Option iface
* Fix grammar in CONTRIBUTING
* Do not store TracerProvider or Tracer fields in SDK recordingSpan (#2575)
* Do not store TracerProvider fields in span
Instead of keeping a reference to the span's Tracer, and therefore also
it's TracerProvider, and the associated resource and spanLimits just
keep the reference to the Tracer. Refer to the TracerProvider fields
when needed instead.
* Make span refer to the inst lib via the Tracer
Instead of holding a field in the span, refer to the field in the parent
Tracer.
* [website_docs] fix page meta-links (#2580)
Contributes to https://github.com/open-telemetry/opentelemetry.io/issues/1096
/cc @cartermp @austinlparker
* Validate members once, in `NewMember` (#2522)
* use NewMember, or specify if the member is not validated when creating new ones
* expect members to already be validated when creating a new package
* add changelog entry
* add an isEmpty field to member and property for quick validation
* rename isEmpty to hasData
So by default, an empty struct really is marked as having no data
* Update baggage/baggage_test.go
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* don't validate the member in parseMember, we alredy ran that validation
We also don't want to use NewMember, as that runs the property
validation again, making the benchmark quite slower
* move changelog entry to the fixed section
* provide the member/property data when returning an invalid error
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* Fix link to Zipkin exporter (#2581)
Currently it is linked to the old package that was moved.
* Unexport EnvBatchSpanProcessor* constants (#2583)
* Move BSP env support to internal
* Use pkg name
* Update env test
* Use internal/env in sdk/trace
* Avoid an extra allocation in applyTracerProviderEnvConfigs.
* Add additional errors for ratio > 1.0.
* Add test cases for ratio > 1.0.
* Update CHANGELOG.md
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
Co-authored-by: jaychung <ken8203@gmail.com>
Co-authored-by: Ben Wells <b.v.wells@gmail.com>
Co-authored-by: Jeremy Kaplan <jeremy@stytch.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: thinkgo <49174849+thinkgos@users.noreply.github.com>
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Chao Weng <19381524+sincejune@users.noreply.github.com>
Co-authored-by: Patrice Chalin <chalin@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2022-03-21 18:39:30 +02:00
|
|
|
// This option overrides the Sampler configured through the OTEL_TRACES_SAMPLER
|
|
|
|
// and OTEL_TRACES_SAMPLER_ARG environment variables. If this option is not used
|
|
|
|
// and the sampler is not configured through environment variables or the environment
|
|
|
|
// contains invalid/unsupported configuration, the TracerProvider will use a
|
2021-03-18 18:34:47 +02:00
|
|
|
// ParentBased(AlwaysSample) Sampler by default.
|
|
|
|
func WithSampler(s Sampler) TracerProviderOption {
|
2022-02-01 23:51:23 +02:00
|
|
|
return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig {
|
2021-03-18 19:48:13 +02:00
|
|
|
if s != nil {
|
2021-05-14 22:28:28 +02:00
|
|
|
cfg.sampler = s
|
2021-03-18 19:48:13 +02:00
|
|
|
}
|
2022-02-01 23:51:23 +02:00
|
|
|
return cfg
|
2021-05-14 22:28:28 +02:00
|
|
|
})
|
2021-03-08 23:43:11 +02:00
|
|
|
}
|
|
|
|
|
2022-03-03 17:56:07 +02:00
|
|
|
// WithSpanLimits returns a TracerProviderOption that configures a
|
|
|
|
// TracerProvider to use the SpanLimits sl. These SpanLimits bound any Span
|
|
|
|
// created by a Tracer from the TracerProvider.
|
|
|
|
//
|
|
|
|
// If any field of sl is zero or negative it will be replaced with the default
|
|
|
|
// value for that field.
|
2021-03-18 18:34:47 +02:00
|
|
|
//
|
2022-03-03 17:56:07 +02:00
|
|
|
// If this or WithRawSpanLimits are not provided, the TracerProvider will use
|
|
|
|
// the limits defined by environment variables, or the defaults if unset.
|
|
|
|
// Refer to the NewSpanLimits documentation for information about this
|
|
|
|
// relationship.
|
|
|
|
//
|
|
|
|
// Deprecated: Use WithRawSpanLimits instead which allows setting unlimited
|
|
|
|
// and zero limits. This option will be kept until the next major version
|
|
|
|
// incremented release.
|
2021-03-08 23:43:11 +02:00
|
|
|
func WithSpanLimits(sl SpanLimits) TracerProviderOption {
|
2022-03-03 17:56:07 +02:00
|
|
|
if sl.AttributeValueLengthLimit <= 0 {
|
|
|
|
sl.AttributeValueLengthLimit = DefaultAttributeValueLengthLimit
|
|
|
|
}
|
|
|
|
if sl.AttributeCountLimit <= 0 {
|
|
|
|
sl.AttributeCountLimit = DefaultAttributeCountLimit
|
|
|
|
}
|
|
|
|
if sl.EventCountLimit <= 0 {
|
|
|
|
sl.EventCountLimit = DefaultEventCountLimit
|
|
|
|
}
|
|
|
|
if sl.AttributePerEventCountLimit <= 0 {
|
|
|
|
sl.AttributePerEventCountLimit = DefaultAttributePerEventCountLimit
|
|
|
|
}
|
|
|
|
if sl.LinkCountLimit <= 0 {
|
|
|
|
sl.LinkCountLimit = DefaultLinkCountLimit
|
|
|
|
}
|
|
|
|
if sl.AttributePerLinkCountLimit <= 0 {
|
|
|
|
sl.AttributePerLinkCountLimit = DefaultAttributePerLinkCountLimit
|
|
|
|
}
|
2022-02-01 23:51:23 +02:00
|
|
|
return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig {
|
2021-05-14 22:28:28 +02:00
|
|
|
cfg.spanLimits = sl
|
2022-02-01 23:51:23 +02:00
|
|
|
return cfg
|
2021-05-14 22:28:28 +02:00
|
|
|
})
|
2021-03-18 19:48:13 +02:00
|
|
|
}
|
|
|
|
|
2022-03-03 17:56:07 +02:00
|
|
|
// WithRawSpanLimits returns a TracerProviderOption that configures a
|
|
|
|
// TracerProvider to use these limits. These limits bound any Span created by
|
|
|
|
// a Tracer from the TracerProvider.
|
|
|
|
//
|
|
|
|
// The limits will be used as-is. Zero or negative values will not be changed
|
|
|
|
// to the default value like WithSpanLimits does. Setting a limit to zero will
|
|
|
|
// effectively disable the related resource it limits and setting to a
|
|
|
|
// negative value will mean that resource is unlimited. Consequentially, this
|
|
|
|
// means that the zero-value SpanLimits will disable all span resources.
|
|
|
|
// Because of this, limits should be constructed using NewSpanLimits and
|
|
|
|
// updated accordingly.
|
|
|
|
//
|
|
|
|
// If this or WithSpanLimits are not provided, the TracerProvider will use the
|
|
|
|
// limits defined by environment variables, or the defaults if unset. Refer to
|
|
|
|
// the NewSpanLimits documentation for information about this relationship.
|
|
|
|
func WithRawSpanLimits(limits SpanLimits) TracerProviderOption {
|
|
|
|
return traceProviderOptionFunc(func(cfg tracerProviderConfig) tracerProviderConfig {
|
|
|
|
cfg.spanLimits = limits
|
|
|
|
return cfg
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
Allow setting the Sampler via environment variables (#2517)
* Allow setting the Sampler via environment variables (#2305)
* Add changelog entry.
* Replace t.Setenv with internaltest/SetEnvVariables for Go <= 1.6.
* Handle the lack of a sampler argument without logging errors.
* Add additional test cases and error checks.
* Refactor documentation.
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
* emitBatchOverhead should only be used for splitting spans into batches (#2512)
* emitBatchOverhead should only be used for splitting spans into batches (#2503)
* limit max packet size parameter
* Add additional errors types, simplify abstractions and error handling
* Make error comparisons less fragile.
* Fix typo in jaeger example (#2524)
* Fix some typos in docs for Go libraries (#2520)
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Fix getting-started.md Run function (#2527)
* Fix getting-started.md Run function, it assigns this new context to a variable shared between connections in to accept loop. Thus creating a growing chain of contexts. so every calculate fibonacci request, all spans in a trace.
* add a comment explaining the reason for that new variable
* update example fib
* Bump github.com/google/go-cmp from 0.5.6 to 0.5.7 across the project (#2545)
* update go-cmp to 0.5.7
* fixes go.sums
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
* Un-escape url coding when parsing baggage. (#2529)
* un-escape url coding when parsing baggage.
* Added changelog
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Bump go.opentelemetry.io/proto/otlp from 0.11.0 to 0.12.0 (#2546)
* Update go.opentelemetry.io/proto/otlp to v0.12.0
* Changelog
* Update CHANGELOG.md
Fix's md linting
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Remove unused sdk/internal/santize (#2549)
* Add links to code examples and docs (#2551)
* Bump github.com/prometheus/client_golang from 1.11.0 to 1.12.0 in /exporters/prometheus (#2541)
* Bump github.com/prometheus/client_golang in /exporters/prometheus
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.11.0 to 1.12.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.11.0...v1.12.0)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* go mod tidy
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
* Optimize evictedQueue implementation and use (#2556)
* Optimize evictedQueue impl and use
Avoid unnecessary allocations in the recordingSpan by using an
evictedQueue type instead of a pointer to one.
Lazy allocate the evictedQueue queue to prevent unnecessary operations
for spans without any use of the queue.
Document the evictedQueue
* Fix grammar
* Add env support for batch span processor (#2515)
* Add env support for batch span processor
* Update changelog
* lint
* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools (#2566)
* Bump golang.org/x/tools from 0.1.8 to 0.1.9 in /internal/tools
Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.1.8 to 0.1.9.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.1.8...v0.1.9)
---
updated-dependencies:
- dependency-name: golang.org/x/tools
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump github.com/golangci/golangci-lint from 1.43.0 to 1.44.0 in /internal/tools (#2567)
* Bump github.com/golangci/golangci-lint in /internal/tools
Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/golangci/golangci-lint/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump github.com/prometheus/client_golang from 1.12.0 to 1.12.1 in /exporters/prometheus (#2570)
* Bump github.com/prometheus/client_golang in /exporters/prometheus
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.12.0 to 1.12.1.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.12.0...v1.12.1)
---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Fix TestBackoffRetry in otlp/internal/retry package (#2562)
* Fix TestBackoffRetry in otlp retry pkg
The delay of the retry is within two times a randomization factor (the
back-off time is delay * random number within [1 - factor, 1 + factor].
This means the waitFunc in TestBackoffRetry needs to check the delay is
within an appropriate delta, not equal to configure initial delay.
* Fix delta value
* Fix delta
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlptrace (#2568)
* Bump google.golang.org/grpc in /exporters/otlp/otlptrace
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /example/otel-collector (#2565)
* Bump google.golang.org/grpc in /example/otel-collector
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Bump google.golang.org/grpc from 1.43.0 to 1.44.0 in /exporters/otlp/otlpmetric (#2572)
* Bump google.golang.org/grpc in /exporters/otlp/otlpmetric
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.43.0 to 1.44.0.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.43.0...v1.44.0)
---
updated-dependencies:
- dependency-name: google.golang.org/grpc
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
* Auto-fix go.sum changes in dependent modules
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: MrAlias <MrAlias@users.noreply.github.com>
* Change Options to accept type not pointer (#2558)
* Change trace options to accept type not pointer
Add benchmark to show allocation improvement.
* Update CONTRIBUTING.md guidelines
* Update all Option iface
* Fix grammar in CONTRIBUTING
* Do not store TracerProvider or Tracer fields in SDK recordingSpan (#2575)
* Do not store TracerProvider fields in span
Instead of keeping a reference to the span's Tracer, and therefore also
it's TracerProvider, and the associated resource and spanLimits just
keep the reference to the Tracer. Refer to the TracerProvider fields
when needed instead.
* Make span refer to the inst lib via the Tracer
Instead of holding a field in the span, refer to the field in the parent
Tracer.
* [website_docs] fix page meta-links (#2580)
Contributes to https://github.com/open-telemetry/opentelemetry.io/issues/1096
/cc @cartermp @austinlparker
* Validate members once, in `NewMember` (#2522)
* use NewMember, or specify if the member is not validated when creating new ones
* expect members to already be validated when creating a new package
* add changelog entry
* add an isEmpty field to member and property for quick validation
* rename isEmpty to hasData
So by default, an empty struct really is marked as having no data
* Update baggage/baggage_test.go
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* don't validate the member in parseMember, we alredy ran that validation
We also don't want to use NewMember, as that runs the property
validation again, making the benchmark quite slower
* move changelog entry to the fixed section
* provide the member/property data when returning an invalid error
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
* Fix link to Zipkin exporter (#2581)
Currently it is linked to the old package that was moved.
* Unexport EnvBatchSpanProcessor* constants (#2583)
* Move BSP env support to internal
* Use pkg name
* Update env test
* Use internal/env in sdk/trace
* Avoid an extra allocation in applyTracerProviderEnvConfigs.
* Add additional errors for ratio > 1.0.
* Add test cases for ratio > 1.0.
* Update CHANGELOG.md
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
Co-authored-by: jaychung <ken8203@gmail.com>
Co-authored-by: Ben Wells <b.v.wells@gmail.com>
Co-authored-by: Jeremy Kaplan <jeremy@stytch.com>
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
Co-authored-by: thinkgo <49174849+thinkgos@users.noreply.github.com>
Co-authored-by: Aaron Clawson <Aaron.Clawson@gmail.com>
Co-authored-by: Aaron Clawson <MadVikingGod@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
Co-authored-by: Chao Weng <19381524+sincejune@users.noreply.github.com>
Co-authored-by: Patrice Chalin <chalin@users.noreply.github.com>
Co-authored-by: Damien Mathieu <42@dmathieu.com>
2022-03-21 18:39:30 +02:00
|
|
|
func applyTracerProviderEnvConfigs(cfg tracerProviderConfig) tracerProviderConfig {
|
|
|
|
for _, opt := range tracerProviderOptionsFromEnv() {
|
|
|
|
cfg = opt.apply(cfg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
|
|
|
func tracerProviderOptionsFromEnv() []TracerProviderOption {
|
|
|
|
var opts []TracerProviderOption
|
|
|
|
|
|
|
|
sampler, err := samplerFromEnv()
|
|
|
|
if err != nil {
|
|
|
|
otel.Handle(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if sampler != nil {
|
|
|
|
opts = append(opts, WithSampler(sampler))
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:48:13 +02:00
|
|
|
// ensureValidTracerProviderConfig ensures that given TracerProviderConfig is valid.
|
2022-02-01 23:51:23 +02:00
|
|
|
func ensureValidTracerProviderConfig(cfg tracerProviderConfig) tracerProviderConfig {
|
2021-03-18 19:48:13 +02:00
|
|
|
if cfg.sampler == nil {
|
|
|
|
cfg.sampler = ParentBased(AlwaysSample())
|
|
|
|
}
|
|
|
|
if cfg.idGenerator == nil {
|
|
|
|
cfg.idGenerator = defaultIDGenerator()
|
|
|
|
}
|
|
|
|
if cfg.resource == nil {
|
|
|
|
cfg.resource = resource.Default()
|
2021-03-08 23:43:11 +02:00
|
|
|
}
|
2022-02-01 23:51:23 +02:00
|
|
|
return cfg
|
2021-03-08 23:43:11 +02:00
|
|
|
}
|