feat: exclude OTEL instrumentation via build tag (#770)

* feat: exclude OTEL instrumentation via build tag

* add readme
This commit is contained in:
Jan-Otto Kröpke 2025-07-16 13:29:59 +02:00 committed by GitHub
parent d09a952410
commit 21e830e275
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 3 deletions

View file

@ -73,6 +73,15 @@ CLIENT_ID=web CLIENT_SECRET=secret ISSUER=http://oidc.local:9998/ SCOPES="openid
> Note: Usernames are suffixed with the hostname (`test-user@localhost` or `test-user@oidc.local`)
### Build Tags
The library uses build tags to enable or disable features. The following build tags are available:
| Build Tag | Description |
|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `no_otel` | Disables the OTel instrumentation, which is enabled by default. This is useful if you do not want to use OTel or if you want to use a different instrumentation library. |
### Server configuration
Example server allows extra configuration using environment variables and could be used for end to

12
internal/otel/otel.go Normal file
View file

@ -0,0 +1,12 @@
//go:build !no_otel
package otel
import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)
func Tracer(name string) trace.Tracer {
return otel.Tracer(name)
}

22
internal/otel/shim.go Normal file
View file

@ -0,0 +1,22 @@
//go:build no_otel
package otel
import (
"context"
)
type FakeTracer struct{}
type FakeSpan struct{}
func Tracer(name string) FakeTracer {
return FakeTracer{}
}
func (t FakeTracer) Start(ctx context.Context, _ string) (context.Context, FakeSpan) {
return ctx, FakeSpan{}
}
func (s FakeSpan) End() {
}

View file

@ -12,7 +12,7 @@ import (
"github.com/go-jose/go-jose/v4"
"github.com/zitadel/logging"
"go.opentelemetry.io/otel"
"github.com/zitadel/oidc/v3/internal/otel"
"golang.org/x/oauth2"
"github.com/zitadel/oidc/v3/pkg/crypto"

View file

@ -8,10 +8,10 @@ import (
"time"
"github.com/go-chi/chi/v5"
jose "github.com/go-jose/go-jose/v4"
"github.com/go-jose/go-jose/v4"
"github.com/rs/cors"
"github.com/zitadel/oidc/v3/internal/otel"
"github.com/zitadel/schema"
"go.opentelemetry.io/otel"
"golang.org/x/text/language"
httphelper "github.com/zitadel/oidc/v3/pkg/http"