Adds support for logs (specify level), metrics (enable metrics and Prometheus /metrics endpoint
and traces (jaeger or otlp) for standalone API server. This will allow any grafana core service
part of standalone apiserver to use logging, metrics and traces as normal.
* Pass OTEL sampling config to plugins
* fix capital letters
* Do not pass sampler env vars if sampling is not configured
* Add tests
* PR review feedback
* Simplify tracing env vars logic
* Update test to reflect pkg/infra/tracing behaviour
* differentiate collector and agent better
* Add back the max packet size
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
---------
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.
Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
* remove opentracing and use otel instead
* add various samplers for jaeger
* remove useless test that is covered in otel now
* we do not need a struct there
* remove old tests
* restore tests that parse various configurations
* check errors in tests
* Update pkg/infra/tracing/tracing_test.go
fix typo
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
* add test for both legacy and new config formats
* use named constants
---------
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
* Add fresh context with timeout and same log properties, re-derive logger
* Unify timeout constants
* Move ctx after shortcut that got added through rebasing
* Unify timeouts
* Port opentracing's SpanFromContext and ContextFromSpan to the grafana tracing package
* Support both opentracing and otel variants
* Better document why we're creating a new ctx
* Add new func to FakeSpan which was added after rebase
* Support grafana-specific traceID key in both tracer implementations
* Tracing: Pass OTLP address and propagation format to plugins
* Fix unit tests
* Fix indentation
* Fix plugin manager integration tests
* Goimports
* Pass plugin version to plugins
* Do not add GF_PLUGIN_VERSION if plugin version is not set, add tests
* Allow disabling plugins distributed tracing on a per-plugin basis
* Moved disabled plugins to tracing.opentelemetry config section
* Pre-allocate DisabledPlugins map to the correct size
* Moved disable tracing setting flags in plugin settings
* Renamed plugin env vars for tracing endpoint and propagation
* Fix plugin initializer tests
* Refactoring: Moved OpentelemetryCfg from pkg/infra to pkg/plugins
* Changed GetSection to Section in parseSettingsOpentelemetry
* Add tests for NewOpentelemetryCfg
* Fix test case names in TestNewOpentelemetryCfg
* OpenTelemetry: Remove redundant error checks
* tracing: Support multiple OTel propagators
Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
* tracing: add TraceIDString method to fix up tests
This method will be useful elsewhere if we want to log the trace ID.
* improve propagation docs
Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
* doc style fix
Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
* Use tracing.TraceIDFromContext instead of adding TraceIDString method
Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
---------
Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
Co-authored-by: Bryan Boreham <bjboreham@gmail.com>
Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
Introduces a FromContext method on the log.Logger interface that
allows contextual key/value pairs to be attached, e.g. per request,
so that any logger using this API will automatically get the per request
context attached. The proposal makes the traceID available for
contextual logger , if available, and would allow logs originating from
a certain HTTP request to be correlated with traceID.
In addition, when tracing not enabled, skip adding
traceID=00000000000000000000000000000000
to logs.
* use common traceID context value for opentracing and opentelemetry
* support sampled trace IDs as well
* inject traceID into NormalResponse on errors
* Finally the test passed
* fix the test
* fix linter
* change the function parameter
Co-authored-by: Ying WANG <ying.wang@grafana.com>
* Separate Tracer interface to TracerService and Tracer
* Fix lint
* Fix:Make it possible to start spans for both opentracing and opentelemetry in ds proxy
* Add span methods, use span interface for rest of tracing
* Fix logs in tracing
* Fix tests that are related to tracing
* Fix resourcepermissions test
* Fix some tests
* Fix more tests
* Add TracingService to wire cli runner
* Remove GlobalTracer from bus
* Renaming test function
* Remove GlobalTracer from TSDB
* Replace GlobalTracer in api
* Adjust tests to the InitializeForTests func
* Remove GlobalTracer from services
* Remove GlobalTracer
* Remove bus.NewTest
* Remove Tracer interface
* Add InitializeForBus
* Simplify tests
* Clean up tests
* Rename TracerService to Tracer
* Update pkg/middleware/request_tracing.go
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
* Initialize tracer before passing it to SQLStore initialization in commands
* Remove tests for opentracing
* Set span attributes correctly, remove unnecessary trace initiliazation form test
* Add tracer instance to newSQLStore
* Fix changes due to rebase
* Add modified tracing middleware test
* Fix opentracing implementation tags
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
* Add interface Tracer, add Opentelemetry
* Fix lint
* Fix failing tests and return error if config not parsed fo opentelemetry
* Update defaults.ini
Add comment with jaeger url
* go mod tidy
* Remove comments that are not needed
* Move OpentracingSpan to tracing.go
* Add opentelemetry to sample.ini
Fixes#30144
Co-authored-by: dsotirakis <sotirakis.dim@gmail.com>
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
Co-authored-by: spinillos <selenepinillos@gmail.com>
Co-authored-by: Karl Persson <kalle.persson@grafana.com>
Co-authored-by: Leonard Gram <leo@xlson.com>
* check for jaeger env variables if tracing address configuration is empty
* add tests to ensure jaeger host/port variables override the settings
* allow default host and custom port, too
* disallow missing tracing.jaeger section in the config
* check for all errors in tests
* make parseSettings() return an error