Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions cmds/core-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ import (
)

var (
address = flag.String("addr", ":8080", "Local address that the service binds to and listens on for incoming connections")
address = flag.String("addr", ":8080", "Address and port that the service binds to and listens on for incoming connections")
enableSCD = flag.Bool("enable_scd", false, "Enables the Strategic Conflict Detection API")
allowHTTPBaseUrls = flag.Bool("allow_http_base_urls", false, "Enables http scheme for Strategic Conflict Detection API")
enableHTTP = flag.Bool("enable_http", false, "DEPRECATED (replaced by allow_http_base_urls): Enables http scheme for Strategic Conflict Detection API")
timeout = flag.Duration("server timeout", 10*time.Second, "Default timeout for server calls")
locality = flag.String("locality", "", "self-identification string of this DSS instance")
publicEndpoint = flag.String("public_endpoint", "", "Public endpoint to access this DSS instance. Must be an absolute URI")

logFormat = flag.String("log_format", logging.DefaultFormat, "The log format in {json, console}")
logLevel = flag.String("log_level", logging.DefaultLevel.String(), "The log level")
dumpRequests = flag.Bool("dump_requests", false, "Log full HTTP request and response (note: will dump sensitive information to logs; intended only for debugging and/or development)")
profServiceName = flag.String("gcp_prof_service_name", "", "Service name for the Go profiler")
enableOpenTelemetry = flag.Bool("enable_opentelemetry", false, "Enable OpenTelemetry")
logFormat = flag.String("log_format", logging.DefaultFormat, "The log format in {json, console}")
logLevel = flag.String("log_level", logging.DefaultLevel.String(), "The log level")
dumpRequests = flag.Bool("dump_requests", false, "Log full HTTP request and response (note: will dump sensitive information to logs; intended only for debugging and/or development)")
profServiceName = flag.String("gcp_prof_service_name", "", "Service name for the Go profiler")
enableOpenTelemetry = flag.Bool("enable_opentelemetry", false, "Enable OpenTelemetry, including traces and activation metric endpoint")
metricsListeningAddress = flag.String("metrics_addr", ":8079", "Address and port that the OpenTelemetry prometheus service binds to and listens on for incoming connections")

pkFile = flag.String("public_key_files", "", "Path to public Keys to use for JWT decoding, separated by commas.")
jwksEndpoint = flag.String("jwks_endpoint", "", "URL pointing to an endpoint serving JWKS")
Expand Down Expand Up @@ -336,7 +337,7 @@ func main() {

// Set up OpenTelemetry.
if *enableOpenTelemetry {
otelShutdown, err := setupOTelSDK(ctx)
otelShutdown, err := setupOTelSDK(ctx, *metricsListeningAddress)
if err != nil {
logger.Panic("Failed to initialize OpenTelemetry", zap.Error(err))
}
Expand Down
53 changes: 50 additions & 3 deletions cmds/core-service/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ package main

import (
"context"
"errors"
"net/http"

"github.com/interuss/dss/pkg/logging"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
semconv "go.opentelemetry.io/otel/semconv/v1.40.0"
"go.uber.org/zap"
)

// setupOTelSDK bootstraps the OpenTelemetry pipeline.
// If it does not return an error, make sure to call shutdown for proper cleanup.
func setupOTelSDK(ctx context.Context) (func(context.Context) error, error) {
func setupOTelSDK(ctx context.Context, metricsListeningAddress string) (func(context.Context) error, error) {

// Set up propagator.
prop := newPropagator()
Expand All @@ -26,7 +33,17 @@ func setupOTelSDK(ctx context.Context) (func(context.Context) error, error) {
}
otel.SetTracerProvider(tracerProvider)

return tracerProvider.Shutdown, nil
// Set up metrics exporter
meterProvider, err := newMeterProvider(ctx, metricsListeningAddress)
if err != nil {
return nil, err
}
otel.SetMeterProvider(meterProvider)

shutdown := func(ctx context.Context) error {
return errors.Join(tracerProvider.Shutdown(ctx), meterProvider.Shutdown(ctx))
}
return shutdown, nil
}

func newPropagator() propagation.TextMapPropagator {
Expand Down Expand Up @@ -57,3 +74,33 @@ func newTracerProvider(ctx context.Context) (*trace.TracerProvider, error) {
)
return tracerProvider, nil
}

func newMeterProvider(ctx context.Context, listeningAddress string) (*metric.MeterProvider, error) {

exporter, err := prometheus.New()

if err != nil {
return nil, err
}

provider := metric.NewMeterProvider(metric.WithReader(exporter))

// Start the prometheus HTTP server
go serveMetrics(ctx, listeningAddress)

return provider, nil

}

func serveMetrics(ctx context.Context, listeningAddress string) {

logger := logging.WithValuesFromContext(ctx, logging.Logger)

http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(listeningAddress, nil)
if err != nil {
logger.Panic("error serving http", zap.Error(err))
return
}
logger.Info("Prometheus endpoint started", zap.String("listeningAddress", listeningAddress))
}
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ require (
github.com/jackc/pgx/v5 v5.9.2
github.com/jonboulle/clockwork v0.3.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.23.2
github.com/robfig/cron/v3 v3.0.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0
go.opentelemetry.io/otel v1.43.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.39.0
go.opentelemetry.io/otel/exporters/prometheus v0.65.0
go.opentelemetry.io/otel/sdk v1.43.0
go.opentelemetry.io/otel/sdk/metric v1.43.0
go.opentelemetry.io/otel/trace v1.43.0
go.uber.org/multierr v1.10.0
go.uber.org/zap v1.27.0
Expand All @@ -33,6 +36,7 @@ require (
cloud.google.com/go/auth v0.18.1 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
cloud.google.com/go/compute/metadata v0.9.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -48,13 +52,19 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/otlptranslator v1.0.0 // indirect
github.com/prometheus/procfs v0.20.1 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 // indirect
go.opentelemetry.io/otel/metric v1.43.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
Expand Down
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cloud.google.com/go/profiler v0.4.0 h1:ZeRDZbsOBDyRG0OiK0Op1/XWZ3xeLwJc9zjkzczUx
cloud.google.com/go/profiler v0.4.0/go.mod h1:RvPlm4dilIr3oJtAOeFQU9Lrt5RoySHSDj4pTd6TWeU=
cloud.google.com/go/storage v1.39.1 h1:MvraqHKhogCOTXTlct/9C3K3+Uy2jBmFYb3/Sp6dVtY=
cloud.google.com/go/storage v1.39.1/go.mod h1:xK6xZmxZmo+fyP7+DEF6FhNc24/JAe95OLyOHCXFH1o=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down Expand Up @@ -82,18 +84,34 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
github.com/prometheus/otlptranslator v1.0.0 h1:s0LJW/iN9dkIH+EnhiD3BlkkP5QVIUVEoIwkU+A6qos=
github.com/prometheus/otlptranslator v1.0.0/go.mod h1:vRYWnXvI6aWGpsdY/mOT/cbeVRBlPWtBNDb7kGR3uKM=
github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc=
github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
Expand Down Expand Up @@ -124,6 +142,8 @@ go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0 h1:f0cb2XPmrqn4XMy9PNl
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.39.0/go.mod h1:vnakAaFckOMiMtOIhFI2MNH4FYrZzXCYxmb1LlhoGz8=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.39.0 h1:in9O8ESIOlwJAEGTkkf34DesGRAc/Pn8qJ7k3r/42LM=
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.39.0/go.mod h1:Rp0EXBm5tfnv0WL+ARyO/PHBEaEAT8UUHQ6AGJcSq6c=
go.opentelemetry.io/otel/exporters/prometheus v0.65.0 h1:jOveH/b4lU9HT7y+Gfamf18BqlOuz2PWEvs8yM7Q6XE=
go.opentelemetry.io/otel/exporters/prometheus v0.65.0/go.mod h1:i1P8pcumauPtUI4YNopea1dhzEMuEqWP1xoUZDylLHo=
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
Expand All @@ -140,6 +160,8 @@ go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
Expand Down
4 changes: 3 additions & 1 deletion interfaces/openapi-to-go-server/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ def _generate_apis(
"go.opentelemetry.io/otel",
"go.opentelemetry.io/otel/trace",
"github.com/interuss/stacktrace",
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
]
)
+ '\n dsserr "github.com/interuss/dss/pkg/errors"',
+ '\n dsserr "github.com/interuss/dss/pkg/errors"'
+ '\n semconv "go.opentelemetry.io/otel/semconv/v1.40.0"',
"<API_PACKAGE>": api_package,
"<ROUTES>": "\n".join(routes),
"<ROUTING>": "\n".join(rendering.routing(api, api_package)),
Expand Down
4 changes: 4 additions & 0 deletions interfaces/openapi-to-go-server/templates/server.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func (s *APIRouter) Handle(w http.ResponseWriter, r *http.Request) bool {
for _, route := range s.Routes {
if route.Method == r.Method && route.Pattern.MatchString(r.URL.Path) {

if labeler, ok := otelhttp.LabelerFromContext(r.Context()); ok {
labeler.Add(semconv.HTTPRoute(route.Path))
}

// We retrieve the current span from the otelhttp handler to set its name property.
span := trace.SpanFromContext(r.Context())

Expand Down
11 changes: 9 additions & 2 deletions pkg/api/auxv1/server.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ package auxv1
import (
"context"
"fmt"
"net/http"
"regexp"

"github.com/interuss/dss/pkg/api"
dsserr "github.com/interuss/dss/pkg/errors"
"github.com/interuss/stacktrace"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
semconv "go.opentelemetry.io/otel/semconv/v1.40.0"
"go.opentelemetry.io/otel/trace"
"net/http"
"regexp"
)

type APIRouter struct {
Expand All @@ -26,6 +29,10 @@ func (s *APIRouter) Handle(w http.ResponseWriter, r *http.Request) bool {
for _, route := range s.Routes {
if route.Method == r.Method && route.Pattern.MatchString(r.URL.Path) {

if labeler, ok := otelhttp.LabelerFromContext(r.Context()); ok {
labeler.Add(semconv.HTTPRoute(route.Path))
}

// We retrieve the current span from the otelhttp handler to set its name property.
span := trace.SpanFromContext(r.Context())

Expand Down
11 changes: 9 additions & 2 deletions pkg/api/ridv1/server.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"regexp"

"github.com/interuss/dss/pkg/api"
dsserr "github.com/interuss/dss/pkg/errors"
"github.com/interuss/stacktrace"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
semconv "go.opentelemetry.io/otel/semconv/v1.40.0"
"go.opentelemetry.io/otel/trace"
"net/http"
"regexp"
)

type APIRouter struct {
Expand All @@ -27,6 +30,10 @@ func (s *APIRouter) Handle(w http.ResponseWriter, r *http.Request) bool {
for _, route := range s.Routes {
if route.Method == r.Method && route.Pattern.MatchString(r.URL.Path) {

if labeler, ok := otelhttp.LabelerFromContext(r.Context()); ok {
labeler.Add(semconv.HTTPRoute(route.Path))
}

// We retrieve the current span from the otelhttp handler to set its name property.
span := trace.SpanFromContext(r.Context())

Expand Down
11 changes: 9 additions & 2 deletions pkg/api/ridv2/server.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"regexp"

"github.com/interuss/dss/pkg/api"
dsserr "github.com/interuss/dss/pkg/errors"
"github.com/interuss/stacktrace"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
semconv "go.opentelemetry.io/otel/semconv/v1.40.0"
"go.opentelemetry.io/otel/trace"
"net/http"
"regexp"
)

type APIRouter struct {
Expand All @@ -27,6 +30,10 @@ func (s *APIRouter) Handle(w http.ResponseWriter, r *http.Request) bool {
for _, route := range s.Routes {
if route.Method == r.Method && route.Pattern.MatchString(r.URL.Path) {

if labeler, ok := otelhttp.LabelerFromContext(r.Context()); ok {
labeler.Add(semconv.HTTPRoute(route.Path))
}

// We retrieve the current span from the otelhttp handler to set its name property.
span := trace.SpanFromContext(r.Context())

Expand Down
11 changes: 9 additions & 2 deletions pkg/api/scdv1/server.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"regexp"

"github.com/interuss/dss/pkg/api"
dsserr "github.com/interuss/dss/pkg/errors"
"github.com/interuss/stacktrace"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
semconv "go.opentelemetry.io/otel/semconv/v1.40.0"
"go.opentelemetry.io/otel/trace"
"net/http"
"regexp"
)

type APIRouter struct {
Expand All @@ -27,6 +30,10 @@ func (s *APIRouter) Handle(w http.ResponseWriter, r *http.Request) bool {
for _, route := range s.Routes {
if route.Method == r.Method && route.Pattern.MatchString(r.URL.Path) {

if labeler, ok := otelhttp.LabelerFromContext(r.Context()); ok {
labeler.Add(semconv.HTTPRoute(route.Path))
}

// We retrieve the current span from the otelhttp handler to set its name property.
span := trace.SpanFromContext(r.Context())

Expand Down
3 changes: 3 additions & 0 deletions pkg/sqlstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func Dial[R any](ctx context.Context, connParams params.ConnectParameters) (*Sto
if err != nil {
return nil, err
}
if err := otelpgx.RecordStats(dbPool); err != nil {
return nil, err
}

const versionDbQuery = `
SELECT version();
Expand Down
Loading