Skip to content

Commit

Permalink
OpenTelemetry integration: Allow exporting EXPLAIN plans as trace spans
Browse files Browse the repository at this point in the history
This is an experimental feature that allows configuring the collector
to send an OTel tracing span for each processed EXPLAIN plan with an
associated "traceparent" query tag (e.g. set by sqlcommenter) to the
configured OpenTelemetry endpoint.

To configure the endpoint set the new config setting
otel_exporter_otlp_endpoint / OTEL_EXPORTER_OTLP_ENDPOINT, with a
endpoint string like "http://localhost:4318".

The tracing span contains the runtime of the EXPLAIN plan, as determined
from the logs, as well as a backlink to pganalyze as the "url.full" span
attribute, to allow accessing the full details within the pganalyze app.

Overall this aims to enable easy access of pganalyze for slow traces
collected in an APM tool, and helps identify when the database was
the bottleneck (and why). It requires the "traceparent" query tag to be
present on logged EXPLAIN plans, e.g. added by using sqlcommenter within
the application.
  • Loading branch information
lfittl committed Oct 3, 2023
1 parent 4e91a60 commit c480920
Show file tree
Hide file tree
Showing 1,048 changed files with 134,925 additions and 53,277 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ type ServerConfig struct {
FilterQuerySample string `ini:"filter_query_sample"` // none/normalize/all (defaults to "none")
FilterQueryText string `ini:"filter_query_text"` // none/unparsable (defaults to "unparsable")

// Configuration for OpenTelemetry trace exports
OtelExporterOtlpEndpoint string `ini:"otel_exporter_otlp_endpoint"` // See https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/protocol/exporter.md

// HTTP proxy overrides
HTTPProxy string `ini:"http_proxy"`
HTTPSProxy string `ini:"https_proxy"`
Expand Down
3 changes: 3 additions & 0 deletions config/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ func getDefaultConfig() *ServerConfig {
if filterQueryText := os.Getenv("FILTER_QUERY_TEXT"); filterQueryText != "" {
config.FilterQueryText = filterQueryText
}
if otelExporterOtlpEndpoint := os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"); otelExporterOtlpEndpoint != "" {
config.FilterQueryText = otelExporterOtlpEndpoint
}
if httpProxy := os.Getenv("HTTP_PROXY"); httpProxy != "" {
config.HTTPProxy = httpProxy
}
Expand Down
61 changes: 37 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
module github.com/pganalyze/collector

require (
cloud.google.com/go v0.68.0 // indirect
cloud.google.com/go/pubsub v1.8.1
cloud.google.com/go v0.110.4 // indirect
cloud.google.com/go/pubsub v1.32.0
github.com/AlecAivazis/survey/v2 v2.2.1
github.com/StackExchange/wmi v0.0.0-20150520194626-f3e2bae1e0cb // indirect
github.com/aws/aws-sdk-go v1.36.10
Expand All @@ -15,15 +15,14 @@ require (
github.com/go-ini/ini v1.62.0
github.com/go-ole/go-ole v0.0.0-20160708033836-be49f7c07711 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorhill/cronexpr v0.0.0-20160318121724-f0984319b442
github.com/guregu/null v0.0.0-20160228005316-41961cea0328
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/jtolds/gls v4.2.0+incompatible // indirect
github.com/juju/syslog v0.0.0-20150205155936-6be94e8b7187
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
github.com/kr/pretty v0.2.1 // indirect
github.com/kylelemons/godebug v1.1.0
github.com/lib/pq v1.10.7
github.com/ogier/pflag v0.0.0-20160129220114-45c278ab3607
Expand All @@ -33,10 +32,10 @@ require (
github.com/shirou/gopsutil v3.21.10+incompatible
github.com/smartystreets/assertions v0.0.0-20160707190355-2063fd1cc7c9 // indirect
github.com/smartystreets/goconvey v0.0.0-20160704134950-4622128e06c7 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0
google.golang.org/api v0.32.0
google.golang.org/protobuf v1.25.0
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0
google.golang.org/api v0.126.0
google.golang.org/protobuf v1.31.0
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/mcuadros/go-syslog.v2 v2.3.0
)
Expand All @@ -47,38 +46,52 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/messaging/azeventhubs v1.0.0
github.com/pganalyze/pg_query_go/v4 v4.2.1
github.com/prometheus/procfs v0.7.3
go.opentelemetry.io/otel v1.19.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0
go.opentelemetry.io/otel/sdk v1.19.0
go.opentelemetry.io/otel/trace v1.19.0
)

require (
cloud.google.com/go/compute v1.21.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/Azure/go-amqp v1.0.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
go.opencensus.io v0.22.4 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/genproto v0.0.0-20201002142447-3860012362da // indirect
google.golang.org/grpc v1.32.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.2 // indirect
)

go 1.20
Loading

0 comments on commit c480920

Please sign in to comment.