in tracer.go [447:557]
func newTracer(opts TracerOptions) *Tracer {
t := &Tracer{
transport: opts.Transport,
service: makeService(
opts.ServiceName,
opts.ServiceVersion,
opts.ServiceEnvironment,
),
process: ¤tProcess,
system: &localSystem,
closing: make(chan struct{}),
closed: make(chan struct{}),
forceFlush: make(chan chan<- struct{}),
forceSendMetrics: make(chan chan<- struct{}),
configCommands: make(chan tracerConfigCommand),
configWatcher: make(chan apmconfig.Watcher),
events: make(chan tracerEvent, tracerEventChannelCap),
active: 1,
breakdownMetrics: newBreakdownMetrics(),
stats: &TracerStats{},
bufferSize: opts.bufferSize,
metricsBufferSize: opts.metricsBufferSize,
profileSender: opts.profileSender,
versionGetter: opts.versionGetter,
instrumentationConfigInternal: &instrumentationConfig{
local: make(map[string]func(*instrumentationConfigValues)),
},
globalLabels: opts.globalLabels,
}
t.breakdownMetrics.enabled = opts.breakdownMetrics
// Initialise local transaction config.
t.setLocalInstrumentationConfig(envRecording, func(cfg *instrumentationConfigValues) {
cfg.recording = opts.recording
})
t.setLocalInstrumentationConfig(envCaptureBody, func(cfg *instrumentationConfigValues) {
cfg.captureBody = opts.captureBody
})
t.setLocalInstrumentationConfig(envCaptureHeaders, func(cfg *instrumentationConfigValues) {
cfg.captureHeaders = opts.captureHeaders
})
t.setLocalInstrumentationConfig(envMaxSpans, func(cfg *instrumentationConfigValues) {
cfg.maxSpans = opts.maxSpans
})
t.setLocalInstrumentationConfig(envSpanCompressionEnabled, func(cfg *instrumentationConfigValues) {
cfg.compressionOptions.enabled = opts.compressionOptions.enabled
})
t.setLocalInstrumentationConfig(envSpanCompressionExactMatchMaxDuration, func(cfg *instrumentationConfigValues) {
cfg.compressionOptions.exactMatchMaxDuration = opts.compressionOptions.exactMatchMaxDuration
})
t.setLocalInstrumentationConfig(envSpanCompressionSameKindMaxDuration, func(cfg *instrumentationConfigValues) {
cfg.compressionOptions.sameKindMaxDuration = opts.compressionOptions.sameKindMaxDuration
})
t.setLocalInstrumentationConfig(envTransactionSampleRate, func(cfg *instrumentationConfigValues) {
cfg.sampler = opts.sampler
})
t.setLocalInstrumentationConfig(envSpanStackTraceMinDuration, func(cfg *instrumentationConfigValues) {
cfg.spanStackTraceMinDuration = opts.spanStackTraceMinDuration
})
t.setLocalInstrumentationConfig(envStackTraceLimit, func(cfg *instrumentationConfigValues) {
cfg.stackTraceLimit = opts.stackTraceLimit
})
t.setLocalInstrumentationConfig(envUseElasticTraceparentHeader, func(cfg *instrumentationConfigValues) {
cfg.propagateLegacyHeader = opts.propagateLegacyHeader
})
t.setLocalInstrumentationConfig(envSanitizeFieldNames, func(cfg *instrumentationConfigValues) {
cfg.sanitizedFieldNames = opts.sanitizedFieldNames
})
t.setLocalInstrumentationConfig(envIgnoreURLs, func(cfg *instrumentationConfigValues) {
cfg.ignoreTransactionURLs = opts.ignoreTransactionURLs
})
t.setLocalInstrumentationConfig(envExitSpanMinDuration, func(cfg *instrumentationConfigValues) {
cfg.exitSpanMinDuration = opts.exitSpanMinDuration
})
t.setLocalInstrumentationConfig(envContinuationStrategy, func(cfg *instrumentationConfigValues) {
cfg.continuationStrategy = opts.continuationStrategy
})
if logger := apmlog.DefaultLogger(); logger != nil {
defaultLogLevel := logger.Level()
t.setLocalInstrumentationConfig(apmlog.EnvLogLevel, func(cfg *instrumentationConfigValues) {
// Revert to the original, local, log level when
// the centrally defined log level is removed.
logger.SetLevel(defaultLogLevel)
})
}
if !opts.active {
t.active = 0
close(t.closed)
return t
}
go t.loop()
t.configCommands <- func(cfg *tracerConfig) {
cfg.recording = opts.recording
cfg.cpuProfileInterval = opts.cpuProfileInterval
cfg.cpuProfileDuration = opts.cpuProfileDuration
cfg.heapProfileInterval = opts.heapProfileInterval
cfg.metricsInterval = opts.metricsInterval
cfg.requestDuration = opts.requestDuration
cfg.requestSize = opts.requestSize
cfg.disabledMetrics = opts.disabledMetrics
cfg.metricsGatherers = []MetricsGatherer{newBuiltinMetricsGatherer(t)}
if logger := apmlog.DefaultLogger(); logger != nil {
cfg.logger = logger
}
}
if opts.configWatcher != nil {
t.configWatcher <- opts.configWatcher
}
return t
}