Skip to content

Commit 709d41f

Browse files
authored
[observability] most basic OpenTelemetry integration into MCK (#93)
# Summary This pull request introduces OpenTelemetry tracing support to the MongoDB Kubernetes Operator and its related components. Key changes include the integration of OpenTelemetry libraries, the addition of tracing configuration, and updates to ensure trace propagation across the application. These changes enhance observability and debugging capabilities. In our CI suite this means we will have the following kind of traces: ``` trace_id: abc123 ┌────────────────────┐ │ Evergreen │ │ span_id: ROOT │ │ parent_id: none │ └─────────┬──────────┘ │ ┌──────────────────────────┼─────────────────────────┐ ▼ ▼ ▼ ┌──────────────┐ ┌────────────────┐ ┌────────────────────┐ │ E2E Test │ │ Operator │ │ (Other…) │ │ span_id: A1 │ │ span_id: B1 │ │ │ │ parent: ROOT │ │ parent: ROOT │ │ │ └──────┬───────┘ └──────┬─────────┘ └────────────────────┘ │ │ ▼ ▼ ┌──────────────┐ ┌────────────────────┐ │ E2E Function │ │ Reconcile Loop │ │ span_id: A2 │ │ span_id: B2 │ │ parent: A1 │ │ parent: B1 │ └──────────────┘ └────────────────────┘ ``` ### OpenTelemetry Integration: * **Tracing in `main.go`:** - Added OpenTelemetry setup in the `main` function, including trace and span ID extraction from environment variables and the creation of a root span for the operator. Tracing context is propagated across controllers and shutdown processes are handled gracefully. * **Telemetry in `pkg/telemetry/client.go`:** <--- this is good to know if we happen to make a change and happen to send to prod atlas - Added a span to the `SendEventWithRetry` function to capture telemetry events and include the Atlas base URL as a span attribute. ### Helm Chart Updates: * **Operator configuration:** - Added OpenTelemetry-specific environment variables (`OTEL_TRACE_ID`, `OTEL_PARENT_ID`, `OTEL_EXPORTER_OTLP_ENDPOINT`) to the operator's deployment template. (`[helm_chart/templates/operator.yamlR83-R90](diffhunk://#diff-5d2e377a6806023ca9eff60be4d7e5cd879803de2bd3800b630f479f8728f322R83-R90)`) - Introduced OpenTelemetry configuration options (`enabled`, `traceID`, `parentID`, `collectorEndpoint`) in the Helm chart's `values.yaml`. ### Dependency Updates: * **Go module dependencies:** - Added OpenTelemetry-related libraries (`otel`, `otel/sdk`, `otel/trace`, etc.) to `go.mod`. ## Proof of Work - e.g. [patch](https://spruce.mongodb.com/task/mongodb_kubernetes_e2e_mdb_kind_ubi_cloudqa_e2e_replica_set_pv_patch_943128faa1f738781f2b0e7442c8d63077c9ecd5_682dce94ed55bd000781c215_25_05_21_13_01_10/logs?execution=0&sortBy=STATUS&sortDir=ASC) - generated traces in our ci: [Link](https://ui.honeycomb.io/mongodb-4b/environments/production/datasets/evergreen-agent/trace/uNv82G92XFD?fields[]=s_name&fields[]=s_serviceName&span=418471a7ba33179f) ![Screenshot 2025-05-21 at 15 19 20](https://github.com/user-attachments/assets/8a92a157-8618-47ff-ba61-f42a33f7c6b1) ## Checklist - [ ] Have you linked a jira ticket and/or is the ticket in the title? - [x] Have you checked whether your jira ticket required DOCSP changes? - [ ] Have you checked for release_note changes? ## Reminder (Please remove this when merging) - Please try to Approve or Reject Changes the PR, keep PRs in review as short as possible - Our Short Guide for PRs: [Link](https://docs.google.com/document/d/1T93KUtdvONq43vfTfUt8l92uo4e4SEEvFbIEKOxGr44/edit?tab=t.0) - Remember the following Communication Standards - use comment prefixes for clarity: * **blocking**: Must be addressed before approval. * **follow-up**: Can be addressed in a later PR or ticket. * **q**: Clarifying question. * **nit**: Non-blocking suggestions. * **note**: Side-note, non-actionable. Example: Praise * --> no prefix is considered a question
1 parent 7ebb7a2 commit 709d41f

File tree

15 files changed

+347
-67
lines changed

15 files changed

+347
-67
lines changed

LICENSE-THIRD-PARTY

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ github.com/ghodss/yaml,v1.0.0,https://github.com/ghodss/yaml/blob/v1.0.0/LICENSE
1111
github.com/go-jose/go-jose/v4,v4.0.5,https://github.com/go-jose/go-jose/blob/v4.0.5/LICENSE,Apache-2.0
1212
github.com/go-jose/go-jose/v4/json,v4.0.5,https://github.com/go-jose/go-jose/blob/v4.0.5/json/LICENSE,BSD-3-Clause
1313
github.com/go-logr/logr,v1.4.3,https://github.com/go-logr/logr/blob/v1.4.3/LICENSE,Apache-2.0
14+
github.com/go-logr/stdr,v1.2.2,https://github.com/go-logr/stdr/blob/v1.2.2/LICENSE,Apache-2.0
1415
github.com/go-logr/zapr,v1.3.0,https://github.com/go-logr/zapr/blob/v1.3.0/LICENSE,Apache-2.0
1516
github.com/go-openapi/jsonpointer,v0.19.6,https://github.com/go-openapi/jsonpointer/blob/v0.19.6/LICENSE,Apache-2.0
1617
github.com/go-openapi/jsonreference,v0.20.2,https://github.com/go-openapi/jsonreference/blob/v0.20.2/LICENSE,Apache-2.0
@@ -23,6 +24,7 @@ github.com/google/go-cmp/cmp,v0.7.0,https://github.com/google/go-cmp/blob/v0.7.0
2324
github.com/google/go-querystring/query,v1.1.0,https://github.com/google/go-querystring/blob/v1.1.0/LICENSE,BSD-3-Clause
2425
github.com/google/gofuzz,v1.2.0,https://github.com/google/gofuzz/blob/v1.2.0/LICENSE,Apache-2.0
2526
github.com/google/uuid,v1.6.0,https://github.com/google/uuid/blob/v1.6.0/LICENSE,BSD-3-Clause
27+
github.com/grpc-ecosystem/grpc-gateway/v2,v2.16.0,https://github.com/grpc-ecosystem/grpc-gateway/blob/v2.16.0/LICENSE.txt,BSD-3-Clause
2628
github.com/hashicorp/errwrap,v1.1.0,https://github.com/hashicorp/errwrap/blob/v1.1.0/LICENSE,MPL-2.0
2729
github.com/hashicorp/go-cleanhttp,v0.5.2,https://github.com/hashicorp/go-cleanhttp/blob/v0.5.2/LICENSE,MPL-2.0
2830
github.com/hashicorp/go-multierror,v1.1.1,https://github.com/hashicorp/go-multierror/blob/v1.1.1/LICENSE,MPL-2.0
@@ -57,10 +59,21 @@ github.com/stretchr/testify/assert,v1.10.0,https://github.com/stretchr/testify/b
5759
github.com/vmihailenco/msgpack/v5,v5.3.5,https://github.com/vmihailenco/msgpack/blob/v5.3.5/LICENSE,BSD-2-Clause
5860
github.com/vmihailenco/tagparser/v2,v2.0.0,https://github.com/vmihailenco/tagparser/blob/v2.0.0/LICENSE,BSD-2-Clause
5961
github.com/xdg/stringprep,v1.0.3,https://github.com/xdg/stringprep/blob/v1.0.3/LICENSE,Apache-2.0
62+
go.opentelemetry.io/auto/sdk,v1.1.0,https://github.com/open-telemetry/opentelemetry-go-instrumentation/blob/sdk/v1.1.0/sdk/LICENSE,Apache-2.0
63+
go.opentelemetry.io/otel,v1.35.0,https://github.com/open-telemetry/opentelemetry-go/blob/v1.35.0/LICENSE,Apache-2.0
64+
go.opentelemetry.io/otel/exporters/otlp/otlptrace,v1.19.0,https://github.com/open-telemetry/opentelemetry-go/blob/exporters/otlp/otlptrace/v1.19.0/exporters/otlp/otlptrace/LICENSE,Apache-2.0
65+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc,v1.19.0,https://github.com/open-telemetry/opentelemetry-go/blob/exporters/otlp/otlptrace/otlptracegrpc/v1.19.0/exporters/otlp/otlptrace/otlptracegrpc/LICENSE,Apache-2.0
66+
go.opentelemetry.io/otel/metric,v1.35.0,https://github.com/open-telemetry/opentelemetry-go/blob/metric/v1.35.0/metric/LICENSE,Apache-2.0
67+
go.opentelemetry.io/otel/sdk,v1.35.0,https://github.com/open-telemetry/opentelemetry-go/blob/sdk/v1.35.0/sdk/LICENSE,Apache-2.0
68+
go.opentelemetry.io/otel/trace,v1.35.0,https://github.com/open-telemetry/opentelemetry-go/blob/trace/v1.35.0/trace/LICENSE,Apache-2.0
69+
go.opentelemetry.io/proto/otlp,v1.0.0,https://github.com/open-telemetry/opentelemetry-proto-go/blob/otlp/v1.0.0/otlp/LICENSE,Apache-2.0
6070
go.uber.org/multierr,v1.11.0,https://github.com/uber-go/multierr/blob/v1.11.0/LICENSE.txt,MIT
6171
go.uber.org/zap,v1.27.0,https://github.com/uber-go/zap/blob/v1.27.0/LICENSE,MIT
6272
go.yaml.in/yaml/v2,v2.4.2,https://github.com/yaml/go-yaml/blob/v2.4.2/LICENSE,Apache-2.0
6373
gomodules.xyz/jsonpatch/v2,v2.4.0,https://github.com/gomodules/jsonpatch/blob/v2.4.0/v2/LICENSE,Apache-2.0
74+
google.golang.org/genproto/googleapis/api/httpbody,v0.0.0-20230726155614-23370e0ffb3e,https://github.com/googleapis/go-genproto/blob/23370e0ffb3e/googleapis/api/LICENSE,Apache-2.0
75+
google.golang.org/genproto/googleapis/rpc,v0.0.0-20230822172742-b8732ec3820d,https://github.com/googleapis/go-genproto/blob/b8732ec3820d/googleapis/rpc/LICENSE,Apache-2.0
76+
google.golang.org/grpc,v1.58.3,https://github.com/grpc/grpc-go/blob/v1.58.3/LICENSE,Apache-2.0
6477
google.golang.org/protobuf,v1.36.5,https://github.com/protocolbuffers/protobuf-go/blob/v1.36.5/LICENSE,BSD-3-Clause
6578
gopkg.in/inf.v0,v0.9.1,https://github.com/go-inf/inf/blob/v0.9.1/LICENSE,BSD-3-Clause
6679
gopkg.in/natefinch/lumberjack.v2,v2.2.1,https://github.com/natefinch/lumberjack/blob/v2.2.1/LICENSE,MIT

docker/mongodb-kubernetes-tests/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_operator_installation_config(namespace):
111111
config = KubernetesTester.read_configmap(namespace, "operator-installation-config")
112112
config["customEnvVars"] = f"OPS_MANAGER_MONITOR_APPDB={MONITOR_APPDB_E2E_DEFAULT}"
113113
if os.getenv("OM_DEBUG_HTTP") == "true":
114-
print("Adding OM_DEBUG_HTTP=true to operator_installation_config")
114+
logger.debug("Adding OM_DEBUG_HTTP=true to operator_installation_config")
115115
config["customEnvVars"] += "\&OM_DEBUG_HTTP=true"
116116

117117
if local_operator():
@@ -1642,7 +1642,7 @@ def configure_telemetry():
16421642
tracer_provider.add_span_processor(prefix_processor)
16431643

16441644

1645-
# Remove the OpenTelemetryPlugin form the list and replace it with our custom generated one.
1645+
# Remove the OpenTelemetryPlugin from the list and replace it with our custom generated one.
16461646
# That's why we run our pytest last.
16471647
@pytest.hookimpl(trylast=True)
16481648
def pytest_configure(config):

go.mod

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ require (
2424
github.com/yudai/gojsondiff v1.0.0
2525
go.mongodb.org/atlas v0.38.0
2626
go.mongodb.org/mongo-driver v1.17.4
27+
go.opentelemetry.io/otel v1.35.0
28+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0
29+
go.opentelemetry.io/otel/sdk v1.35.0
30+
go.opentelemetry.io/otel/trace v1.35.0
2731
go.uber.org/zap v1.27.0
2832
golang.org/x/crypto v0.39.0
2933
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
@@ -52,6 +56,7 @@ require (
5256
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
5357
github.com/fsnotify/fsnotify v1.7.0 // indirect
5458
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
59+
github.com/go-logr/stdr v1.2.2 // indirect
5560
github.com/go-openapi/jsonpointer v0.19.6 // indirect
5661
github.com/go-openapi/jsonreference v0.20.2 // indirect
5762
github.com/go-openapi/swag v0.22.3 // indirect
@@ -63,6 +68,7 @@ require (
6368
github.com/google/go-querystring v1.1.0 // indirect
6469
github.com/google/gofuzz v1.2.0 // indirect
6570
github.com/gorilla/websocket v1.5.0 // indirect
71+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
6672
github.com/hashicorp/errwrap v1.1.0 // indirect
6773
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
6874
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
@@ -99,6 +105,10 @@ require (
99105
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
100106
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
101107
github.com/yudai/pp v2.0.1+incompatible // indirect
108+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
109+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
110+
go.opentelemetry.io/otel/metric v1.35.0 // indirect
111+
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
102112
go.uber.org/multierr v1.11.0 // indirect
103113
go.yaml.in/yaml/v2 v2.4.2 // indirect
104114
golang.org/x/mod v0.25.0 // indirect
@@ -111,6 +121,9 @@ require (
111121
golang.org/x/time v0.3.0 // indirect
112122
golang.org/x/tools v0.33.0 // indirect
113123
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
124+
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect
125+
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
126+
google.golang.org/grpc v1.58.3 // indirect
114127
gopkg.in/inf.v0 v0.9.1 // indirect
115128
gopkg.in/yaml.v2 v2.4.0 // indirect
116129
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)