Files
zitadel/internal/zerrors/kind_enumer.go
T
Tim MöhlmannandGitHub eb22b58756 feat(telemetry): improved instrumentation for observability (#11159)
# Which Problems Are Solved

Zitadel did not provide easy correlation between errors, logs, traces
and metrics. The configuration for those instrumentations was also not
consistent, with some supporting different exporters then others.
Implementation and parsing of config was also spaghettified over
multiple packages, with awkward parsing and inconsistent naming of
options.

# How the Problems Are Solved

All telemetry is now merged under the name "instrumentation". Why?
1. We thought it was a good idea in the past to call the milestone
exporter `Telemtry` in the runtime config. Calling this `TelemetryV2`
looks weird.
2. Not everything is a meter and not everything is sent (tele...). 
3. It's also
[defined](https://opentelemetry.io/docs/concepts/instrumentation/) as
such by the OTEL documentation.

## New features

- Adds structured, context based logging with trace-ID awareness
- Static log fields are added to the context, such as service and
request path
- Static log fields are injected in each logline emitted by the
application
- Structured logs can also be send to an otel exporter
- Structured logs can be printed to StdErr in text and JSON format
- Error sinks make sure every error is logged at the correct level:
- Warnings for client side errors (HTTP 400 range, Invalid request etc)
  - Error for server side errors (Internal server errors)
- Metrics can now also be send to a OTEL collector. (previously they
could only be scraped from `/debug/metrics` with prometheus)

## Exporters

This change adds all the exporters supported by OTEL upstream and some
google specific exporters for our cloud deployment.

- StdOut / StdErr: all instrumentations
- OTEL gRPC / HTTP: all instrumentations
- Google: all instrumentations except logging
- Prometheus (pull-based): only metrics

The exception is profiling, which only supports the google exporting due
to lack of support by OTEL upstream.

## Configuration and structure 

- All instrumentation is moved into the new `backend/v3/instrumentation`
package. It reuses configuration types, so both code and runtime
configuration are easier to understand.
- The `internal/telemetry` packages are removed.
- Instrumentation is started with a single function and a proper
shutdown function is now provided.
- Legacy configuration is still parsed from the runtime config, as long
as the new configuration is disabled. This allows backporting this
feature to v4 without breaking existing configurations.

# Additional Changes

- Devcontainer: set `$PATH` variable so installed go binaries can be run
individually, without NX.
- NX: install GCI tool to fix imports

# Additional Context

- Closes https://github.com/zitadel/zitadel/issues/8408
- Closes https://github.com/zitadel/zitadel/issues/6664
- Backport to v4
2026-01-12 05:51:39 +00:00

154 lines
4.8 KiB
Go

// Code generated by "enumer -type=Kind -trimprefix=Kind -json"; DO NOT EDIT.
package zerrors
import (
"encoding/json"
"fmt"
"strings"
)
const _KindName = "CanceledUnknownInvalidArgumentDeadlineExceededNotFoundAlreadyExistsPermissionDeniedResourceExhaustedPreconditionFailedAbortedOutOfRangeUnimplementedInternalUnavailableDataLossUnauthenticated"
var _KindIndex = [...]uint8{0, 8, 15, 30, 46, 54, 67, 83, 100, 118, 125, 135, 148, 156, 167, 175, 190}
const _KindLowerName = "canceledunknowninvalidargumentdeadlineexceedednotfoundalreadyexistspermissiondeniedresourceexhaustedpreconditionfailedabortedoutofrangeunimplementedinternalunavailabledatalossunauthenticated"
func (i Kind) String() string {
i -= 1
if i < 0 || i >= Kind(len(_KindIndex)-1) {
return fmt.Sprintf("Kind(%d)", i+1)
}
return _KindName[_KindIndex[i]:_KindIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _KindNoOp() {
var x [1]struct{}
_ = x[KindCanceled-(1)]
_ = x[KindUnknown-(2)]
_ = x[KindInvalidArgument-(3)]
_ = x[KindDeadlineExceeded-(4)]
_ = x[KindNotFound-(5)]
_ = x[KindAlreadyExists-(6)]
_ = x[KindPermissionDenied-(7)]
_ = x[KindResourceExhausted-(8)]
_ = x[KindPreconditionFailed-(9)]
_ = x[KindAborted-(10)]
_ = x[KindOutOfRange-(11)]
_ = x[KindUnimplemented-(12)]
_ = x[KindInternal-(13)]
_ = x[KindUnavailable-(14)]
_ = x[KindDataLoss-(15)]
_ = x[KindUnauthenticated-(16)]
}
var _KindValues = []Kind{KindCanceled, KindUnknown, KindInvalidArgument, KindDeadlineExceeded, KindNotFound, KindAlreadyExists, KindPermissionDenied, KindResourceExhausted, KindPreconditionFailed, KindAborted, KindOutOfRange, KindUnimplemented, KindInternal, KindUnavailable, KindDataLoss, KindUnauthenticated}
var _KindNameToValueMap = map[string]Kind{
_KindName[0:8]: KindCanceled,
_KindLowerName[0:8]: KindCanceled,
_KindName[8:15]: KindUnknown,
_KindLowerName[8:15]: KindUnknown,
_KindName[15:30]: KindInvalidArgument,
_KindLowerName[15:30]: KindInvalidArgument,
_KindName[30:46]: KindDeadlineExceeded,
_KindLowerName[30:46]: KindDeadlineExceeded,
_KindName[46:54]: KindNotFound,
_KindLowerName[46:54]: KindNotFound,
_KindName[54:67]: KindAlreadyExists,
_KindLowerName[54:67]: KindAlreadyExists,
_KindName[67:83]: KindPermissionDenied,
_KindLowerName[67:83]: KindPermissionDenied,
_KindName[83:100]: KindResourceExhausted,
_KindLowerName[83:100]: KindResourceExhausted,
_KindName[100:118]: KindPreconditionFailed,
_KindLowerName[100:118]: KindPreconditionFailed,
_KindName[118:125]: KindAborted,
_KindLowerName[118:125]: KindAborted,
_KindName[125:135]: KindOutOfRange,
_KindLowerName[125:135]: KindOutOfRange,
_KindName[135:148]: KindUnimplemented,
_KindLowerName[135:148]: KindUnimplemented,
_KindName[148:156]: KindInternal,
_KindLowerName[148:156]: KindInternal,
_KindName[156:167]: KindUnavailable,
_KindLowerName[156:167]: KindUnavailable,
_KindName[167:175]: KindDataLoss,
_KindLowerName[167:175]: KindDataLoss,
_KindName[175:190]: KindUnauthenticated,
_KindLowerName[175:190]: KindUnauthenticated,
}
var _KindNames = []string{
_KindName[0:8],
_KindName[8:15],
_KindName[15:30],
_KindName[30:46],
_KindName[46:54],
_KindName[54:67],
_KindName[67:83],
_KindName[83:100],
_KindName[100:118],
_KindName[118:125],
_KindName[125:135],
_KindName[135:148],
_KindName[148:156],
_KindName[156:167],
_KindName[167:175],
_KindName[175:190],
}
// KindString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func KindString(s string) (Kind, error) {
if val, ok := _KindNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _KindNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Kind values", s)
}
// KindValues returns all values of the enum
func KindValues() []Kind {
return _KindValues
}
// KindStrings returns a slice of all String values of the enum
func KindStrings() []string {
strs := make([]string, len(_KindNames))
copy(strs, _KindNames)
return strs
}
// IsAKind returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Kind) IsAKind() bool {
for _, v := range _KindValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for Kind
func (i Kind) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for Kind
func (i *Kind) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("Kind should be a string, got %s", data)
}
var err error
*i, err = KindString(s)
return err
}