Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat: otel datadog setup (#1323)

Will Hutchinsondef43d255b3d
diff --git a/infra/packages/resources/src/resources/datadog.ts b/infra/packages/resources/src/resources/datadog.ts
index f41142c8b4..aa04713b28 100644
--- a/infra/packages/resources/src/resources/datadog.ts
+++ b/infra/packages/resources/src/resources/datadog.ts
@@ -120,29 +120,36 @@ export const datadogAgentContainer = {
name: 'DD_API_KEY',
value: DATADOG_API_KEY,
},
- // NOTE: this is purposfully commented out because we do not use OTLP and
- // this was causing 1GB/s of data to be written to disk
- // {
- // name: 'DD_APM_ENABLED',
- // value: 'true',
- // },
- // {
- // name: 'DD_LOGS_ENABLED',
- // value: 'true',
- // },
- // {
- // name: 'DD_OTLP_CONFIG_LOGS_ENABLED',
- // value: 'true',
- // },
- // {
- // name: 'DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT',
- // value: '0.0.0.0:4317',
- // },
+ // APM/Tracing configuration
+ {
+ name: 'DD_APM_ENABLED',
+ value: 'true',
+ },
+ {
+ name: 'DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT',
+ value: '0.0.0.0:4317',
+ },
+ // Sampling configuration to prevent excessive disk writes
+ // Sample 10% of traces in prod, 100% in dev for debugging
+ {
+ name: 'DD_APM_SAMPLE_RATE',
+ value: stack === 'prod' ? '0.1' : '1.0',
+ },
+ // Limit max traces per second to prevent runaway costs
+ {
+ name: 'DD_APM_MAX_TPS',
+ value: '100',
+ },
+ // Disable disk buffering to prevent the 1GB/s disk write issue
+ {
+ name: 'DD_APM_RECEIVER_SOCKET',
+ value: '',
+ },
+ ],
+ portMappings: [
+ {
+ containerPort: 4317,
+ },
],
- // portMappings: [
- // {
- // containerPort: 4317,
- // },
- // ],
memoryReservation: 256,
} satisfies ecs.TaskDefinitionContainerDefinitionArgs;
diff --git a/infra/stacks/authentication-service/index.ts b/infra/stacks/authentication-service/index.ts
index d44040d2f9..d275ebf40a 100644
--- a/infra/stacks/authentication-service/index.ts
+++ b/infra/stacks/authentication-service/index.ts
@@ -281,6 +281,15 @@ const service = new AuthenticationService('authentication-service', {
name: 'STRIPE_PREMIUM_PRICE_ID',
value: pulumi.interpolate`${STRIPE_PREMIUM_PRICE_ID}`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'authentication-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
});
diff --git a/infra/stacks/cloud-storage-service/index.ts b/infra/stacks/cloud-storage-service/index.ts
index 3bf8d913f5..688f909228 100644
--- a/infra/stacks/cloud-storage-service/index.ts
+++ b/infra/stacks/cloud-storage-service/index.ts
@@ -301,13 +301,7 @@ const cloudStorageService = new CloudStorageService(
},
{
name: 'RUST_LOG',
- value: `warn,document_storage_service=${
- stack === 'prod' ? 'debug' : 'trace'
- },comms_service=${
- stack === 'prod' ? 'debug' : 'trace'
- },tower_http=info,macro_share_permissions=${
- stack === 'prod' ? 'error' : 'trace'
- },macro_project_utils=info,macro_notify=info`,
+ value: 'info',
},
{
name: 'DOCUMENT_STORAGE_BUCKET',
@@ -422,6 +416,15 @@ const cloudStorageService = new CloudStorageService(
name: 'CONTACTS_QUEUE',
value: pulumi.interpolate`${contactsQueueName}`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'cloud-storage-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
isPrivate: false,
tags,
diff --git a/infra/stacks/connection-gateway/index.ts b/infra/stacks/connection-gateway/index.ts
index e0fd367c81..74800c658d 100644
--- a/infra/stacks/connection-gateway/index.ts
+++ b/infra/stacks/connection-gateway/index.ts
@@ -138,6 +138,15 @@ const connectionGateway = new ConnectionGateway(`connection-gateway-${stack}`, {
name: 'MACRO_DB_URL',
value: pulumi.interpolate`${MACRO_DB_URL}`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'connection-gateway',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
isPrivate: false,
tags,
diff --git a/infra/stacks/contacts-service/index.ts b/infra/stacks/contacts-service/index.ts
index 61435f0fe6..74bcccd88c 100644
--- a/infra/stacks/contacts-service/index.ts
+++ b/infra/stacks/contacts-service/index.ts
@@ -97,6 +97,15 @@ let containerEnvVars = [
name: 'CONNECTION_GATEWAY_URL',
value: `https://connection-gateway${stack === 'prod' ? '' : `-${stack}`}.macro.com`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'contacts-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
];
const cloudStorageStack = new pulumi.StackReference('cloud-storage-stack', {
diff --git a/infra/stacks/convert-service/index.ts b/infra/stacks/convert-service/index.ts
index 28125062a7..05107584af 100644
--- a/infra/stacks/convert-service/index.ts
+++ b/infra/stacks/convert-service/index.ts
@@ -103,6 +103,15 @@ let containerEnvVars = [
name: 'WEB_SOCKET_RESPONSE_LAMBDA',
value: pulumi.interpolate`${jobUpdateHandlerLambdaName}`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'convert-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
];
const convertService = new ConvertService('convert-service', {
diff --git a/infra/stacks/delete-document-worker/index.ts b/infra/stacks/delete-document-worker/index.ts
index c6a46e74d5..00f97f7b8a 100644
--- a/infra/stacks/delete-document-worker/index.ts
+++ b/infra/stacks/delete-document-worker/index.ts
@@ -113,6 +113,15 @@ const deleteDocumentWorker = new Worker(`delete-document-worker-${stack}`, {
stack === 'prod' ? '' : `-${stack === 'dev' ? 'dev3' : stack}`
}.macroverse.workers.dev`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'delete-document-worker',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
cloudStorageClusterName: cloudStorageClusterName,
deleteDocumentQueueArn: deleteDocumentQueueArn,
diff --git a/infra/stacks/document-cognition-service/index.ts b/infra/stacks/document-cognition-service/index.ts
index fe2cb16843..b3b955ce42 100644
--- a/infra/stacks/document-cognition-service/index.ts
+++ b/infra/stacks/document-cognition-service/index.ts
@@ -312,6 +312,15 @@ const documentCognitionService = new DocumentCognitionService(
name: 'AUTHENTICATION_SERVICE_SECRET_KEY',
value: AUTHENTICATION_SERVICE_INTERNAL_API_KEY_SECRET_NAME,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'document-cognition-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
isPrivate: false,
tags,
diff --git a/infra/stacks/email-service/index.ts b/infra/stacks/email-service/index.ts
index da404068a6..1c0abc9dd6 100644
--- a/infra/stacks/email-service/index.ts
+++ b/infra/stacks/email-service/index.ts
@@ -514,6 +514,15 @@ const containerEnvVars = [
name: 'EMAIL_SERVICE_CLOUDFRONT_SIGNER_PUBLIC_KEY_ID',
value: pulumi.interpolate`${cloudfrontDistribution.publicKey.id}`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'email-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
];
const emailService = new EmailService('email-service', {
diff --git a/infra/stacks/notification-service/index.ts b/infra/stacks/notification-service/index.ts
index 838c416557..f6a4fab56e 100644
--- a/infra/stacks/notification-service/index.ts
+++ b/infra/stacks/notification-service/index.ts
@@ -256,6 +256,15 @@ const notificationService = new NotificationService('notification-service', {
name: 'AUTHENTICATION_SERVICE_SECRET_KEY',
value: pulumi.interpolate`${AUTHENTICATION_SERVICE_INTERNAL_API_KEY}`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'notification-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
});
diff --git a/infra/stacks/search-processing-service/index.ts b/infra/stacks/search-processing-service/index.ts
index eda8caebe4..7ab8831604 100644
--- a/infra/stacks/search-processing-service/index.ts
+++ b/infra/stacks/search-processing-service/index.ts
@@ -147,6 +147,15 @@ const searchProcessingService = new SearchProcessingService(
name: 'LEXICAL_SERVICE_URL',
value: `https://lexical-service-${stack}.macroverse.workers.dev`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'search-processing-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
tags,
}
diff --git a/infra/stacks/static-file-service/index.ts b/infra/stacks/static-file-service/index.ts
index 27f6fab823..78e163de88 100644
--- a/infra/stacks/static-file-service/index.ts
+++ b/infra/stacks/static-file-service/index.ts
@@ -92,6 +92,15 @@ const containerEnvVars = [
name: 'MACRO_API_TOKEN_PUBLIC_KEY',
value: pulumi.interpolate`${MACRO_API_TOKENS.macroApiTokenPublicKey}`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'static-file-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
];
/// available as env var: DYNAMODB_TABLE_NAME
diff --git a/infra/stacks/unfurl-service/index.ts b/infra/stacks/unfurl-service/index.ts
index a7d4dbd445..af75cc7b4f 100644
--- a/infra/stacks/unfurl-service/index.ts
+++ b/infra/stacks/unfurl-service/index.ts
@@ -44,6 +44,15 @@ const unfurlService = new UnfurlService(`unfurl-service-${stack}`, {
stack === 'prod' ? 'debug' : 'trace'
},tower_http=debug`,
},
+ // OpenTelemetry / Datadog tracing configuration
+ {
+ name: 'DD_SERVICE',
+ value: 'unfurl-service',
+ },
+ {
+ name: 'DD_ENV',
+ value: stack,
+ },
],
isPrivate: false,
tags,
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 77513a8d07..957d931d21 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -4201,6 +4201,19 @@ dependencies = [
"tower-service",
]
+[[package]]
+name = "hyper-timeout"
+version = "0.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0"
+dependencies = [
+ "hyper 1.6.0",
+ "hyper-util",
+ "pin-project-lite",
+ "tokio",
+ "tower-service",
+]
+
[[package]]
name = "hyper-tls"
version = "0.5.0"
@@ -5011,7 +5024,11 @@ version = "0.1.0"
dependencies = [
"dotenvy",
"macro_env",
+ "opentelemetry",
+ "opentelemetry-otlp",
+ "opentelemetry_sdk",
"tracing",
+ "tracing-opentelemetry",
"tracing-panic",
"tracing-subscriber",
"tracing-tree",
@@ -6161,6 +6178,82 @@ dependencies = [
"vcpkg",
]
+[[package]]
+name = "opentelemetry"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b84bcd6ae87133e903af7ef497404dda70c60d0ea14895fc8a5e6722754fc2a0"
+dependencies = [
+ "futures-core",
+ "futures-sink",
+ "js-sys",
+ "pin-project-lite",
+ "thiserror 2.0.17",
+ "tracing",
+]
+
+[[package]]
+name = "opentelemetry-http"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d7a6d09a73194e6b66df7c8f1b680f156d916a1a942abf2de06823dd02b7855d"
+dependencies = [
+ "async-trait",
+ "bytes",
+ "http 1.3.1",
+ "opentelemetry",
+ "reqwest",
+]
+
+[[package]]
+name = "opentelemetry-otlp"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a2366db2dca4d2ad033cad11e6ee42844fd727007af5ad04a1730f4cb8163bf"
+dependencies = [
+ "http 1.3.1",
+ "opentelemetry",
+ "opentelemetry-http",
+ "opentelemetry-proto",
+ "opentelemetry_sdk",
+ "prost",
+ "reqwest",
+ "thiserror 2.0.17",
+ "tokio",
+ "tonic",
+ "tracing",
+]
+
+[[package]]
+name = "opentelemetry-proto"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a7175df06de5eaee9909d4805a3d07e28bb752c34cab57fa9cff549da596b30f"
+dependencies = [
+ "opentelemetry",
+ "opentelemetry_sdk",
+ "prost",
+ "tonic",
+ "tonic-prost",
+]
+
+[[package]]
+name = "opentelemetry_sdk"
+version = "0.31.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e14ae4f5991976fd48df6d843de219ca6d31b01daaab2dad5af2badeded372bd"
+dependencies = [
+ "futures-channel",
+ "futures-executor",
+ "futures-util",
+ "opentelemetry",
+ "percent-encoding",
+ "rand 0.9.0",
+ "thiserror 2.0.17",
+ "tokio",
+ "tokio-stream",
+]
+
[[package]]
name = "ordered-float"
version = "5.1.0"
@@ -6696,6 +6789,29 @@ dependencies = [
"uuid",
]
+[[package]]
+name = "prost"
+version = "0.14.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568"
+dependencies = [
+ "bytes",
+ "prost-derive",
+]
+
+[[package]]
+name = "prost-derive"
+version = "0.14.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b"
+dependencies = [
+ "anyhow",
+ "itertools 0.14.0",
+ "proc-macro2",
+ "quote",
+ "syn 2.0.98",
+]
+
[[package]]
name = "pxfm"
version = "0.1.25"
@@ -7076,6 +7192,7 @@ dependencies = [
"base64 0.22.1",
"bytes",
"encoding_rs",
+ "futures-channel",
"futures-core",
"futures-util",
"h2 0.4.13",
@@ -9009,6 +9126,43 @@ dependencies = [
"tokio",
]
+[[package]]
+name = "tonic"
+version = "0.14.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a286e33f82f8a1ee2df63f4fa35c0becf4a85a0cb03091a15fd7bf0b402dc94a"
+dependencies = [
+ "async-trait",
+ "base64 0.22.1",
+ "bytes",
+ "http 1.3.1",
+ "http-body 1.0.1",
+ "http-body-util",
+ "hyper 1.6.0",
+ "hyper-timeout",
+ "hyper-util",
+ "percent-encoding",
+ "pin-project",
+ "sync_wrapper",
+ "tokio",
+ "tokio-stream",
+ "tower 0.5.2",
+ "tower-layer",
+ "tower-service",
+ "tracing",
+]
+
+[[package]]
+name = "tonic-prost"
+version = "0.14.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6c55a2d6a14174563de34409c9f92ff981d006f56da9c6ecd40d9d4a31500b0"
+dependencies = [
+ "bytes",
+ "prost",
+ "tonic",
+]
+
[[package]]
name = "tower"
version = "0.4.13"
@@ -9032,9 +9186,12 @@ checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
dependencies = [
"futures-core",
"futures-util",
+ "indexmap 2.12.1",
"pin-project-lite",
+ "slab",
"sync_wrapper",
"tokio",
+ "tokio-util",
"tower-layer",
"tower-service",
"tracing",
@@ -9137,6 +9294,22 @@ dependencies = [
"tracing-core",
]
+[[package]]
+name = "tracing-opentelemetry"
+version = "0.32.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1ac28f2d093c6c477eaa76b23525478f38de514fa9aeb1285738d4b97a9552fc"
+dependencies = [
+ "js-sys",
+ "opentelemetry",
+ "smallvec",
+ "tracing",
+ "tracing-core",
+ "tracing-log",
+ "tracing-subscriber",
+ "web-time",
+]
+
[[package]]
name = "tracing-panic"
version = "0.1.2"
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 4296f5bced..be00a33427 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -196,7 +196,11 @@ tower-http = { version = "0.6.1", features = [
"cors",
"trace",
] }
+opentelemetry = "0.31.0"
+opentelemetry_sdk = { version = "0.31.0", features = ["rt-tokio"] }
+opentelemetry-otlp = { version = "0.31.0", features = ["grpc-tonic"] }
tracing = "0.1.44"
+tracing-opentelemetry = "0.32.1"
tracing-subscriber = { version = "0.3.22", features = ["env-filter", "json"] }
tracing-tree = "0.4.0"
unsynn = "0.3"
diff --git a/rust/cloud-storage/deny.toml b/rust/cloud-storage/deny.toml
index e7c7990fef..75917be48b 100644
--- a/rust/cloud-storage/deny.toml
+++ b/rust/cloud-storage/deny.toml
@@ -181,9 +181,13 @@ allow = [
]
# List of crates to deny
deny = [
+ { crate = "aws-config", wrappers = [
+ "macro_aws_config",
+ ], reason = "Use macro_aws_config for AWS configuration in workspace crates" },
{ crate = "tracing-subscriber", wrappers = [
"lambda_runtime_api_client", # External crate allowed to use tracing-subscriber
"macro_entrypoint",
+ "tracing-opentelemetry", # OpenTelemetry integration requires tracing-subscriber
"tracing-panic", # External crate allowed to use tracing-subscriber
"tracing-tree",
], reason = "Use macro_entrypoint for tracing setup in workspace crates" },
diff --git a/rust/cloud-storage/macro_entrypoint/Cargo.toml b/rust/cloud-storage/macro_entrypoint/Cargo.toml
index 68aa7163d3..2de2ef2433 100644
--- a/rust/cloud-storage/macro_entrypoint/Cargo.toml
+++ b/rust/cloud-storage/macro_entrypoint/Cargo.toml
@@ -7,7 +7,11 @@ version = "0.1.0"
[dependencies]
dotenvy = { workspace = true }
macro_env = { path = "../macro_env" }
+opentelemetry = { workspace = true }
+opentelemetry_sdk = { workspace = true }
+opentelemetry-otlp = { workspace = true }
tracing = { workspace = true }
+tracing-opentelemetry = { workspace = true }
tracing-panic = "0.1"
tracing-subscriber = { workspace = true }
tracing-tree = { workspace = true }
diff --git a/rust/cloud-storage/macro_entrypoint/src/lib.rs b/rust/cloud-storage/macro_entrypoint/src/lib.rs
index 18923646ee..5bd7128151 100644
--- a/rust/cloud-storage/macro_entrypoint/src/lib.rs
+++ b/rust/cloud-storage/macro_entrypoint/src/lib.rs
@@ -3,7 +3,10 @@
//! This is used to provide consistent behaviour with e.g. tracing configurations
use macro_env::Environment;
-use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt};
+use opentelemetry::trace::TracerProvider as _;
+use opentelemetry_otlp::WithExportConfig;
+use opentelemetry_sdk::trace::SdkTracerProvider;
+use tracing_subscriber::{EnvFilter, Registry, layer::SubscriberExt, util::SubscriberInitExt};
use tracing_tree::HierarchicalLayer;
/// unit struct which defines the behaviour for instantiation
@@ -25,7 +28,21 @@ impl Default for MacroEntrypoint {
/// sentinel struct which guarantees that we called [MacroEntrypoint::init]
#[derive(Debug)]
-pub struct InitializedEntrypoint(());
+pub struct InitializedEntrypoint {
+ tracer_provider: Option<SdkTracerProvider>,
+}
+
+impl InitializedEntrypoint {
+ /// Gracefully shut down the OpenTelemetry tracer provider.
+ /// This should be called before the application exits to ensure all traces are flushed.
+ pub fn shutdown(&self) {
+ if let Some(ref provider) = self.tracer_provider
+ && let Err(e) = provider.shutdown()
+ {
+ tracing::error!(error=?e, "failed to shutdown tracer provider");
+ }
+ }
+}
impl MacroEntrypoint {
/// create a new instance of [Self] from an input [Environment]
@@ -53,6 +70,9 @@ impl MacroEntrypoint {
.with_line_number(true)
.pretty()
.init();
+ InitializedEntrypoint {
+ tracer_provider: None,
+ }
}
(
Environment::Local,
@@ -62,22 +82,40 @@ impl MacroEntrypoint {
) => {
let subscriber = Registry::default().with(HierarchicalLayer::new(level));
tracing::subscriber::set_global_default(subscriber).unwrap();
+ InitializedEntrypoint {
+ tracer_provider: None,
+ }
}
(Environment::Production | Environment::Develop, _) => {
- tracing_subscriber::fmt()
+ let tracer_provider = init_opentelemetry();
+
+ // Get service name for the tracer
+ let service_name =
+ std::env::var("DD_SERVICE").unwrap_or_else(|_| "unknown-service".to_string());
+
+ let tracer = tracer_provider.tracer(service_name);
+ let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer);
+
+ let fmt_layer = tracing_subscriber::fmt::layer()
.with_ansi(false)
- .with_env_filter(EnvFilter::from_default_env())
.with_file(true)
.with_line_number(true)
.json()
.with_current_span(true)
.with_span_list(false)
- .flatten_event(true)
+ .flatten_event(true);
+
+ Registry::default()
+ .with(EnvFilter::from_default_env())
+ .with(fmt_layer)
+ .with(otel_layer)
.init();
+
+ InitializedEntrypoint {
+ tracer_provider: Some(tracer_provider),
+ }
}
}
-
- InitializedEntrypoint(())
}
/// begin modifying the options for the local environment
@@ -89,6 +127,36 @@ impl MacroEntrypoint {
}
}
+/// Opentelemetry export endpoint to talk with datadog sidecar
+const OTEL_EXPORTER_OTLP_ENDPOINT: &str = "http://127.0.0.1:4317";
+
+/// Initialize OpenTelemetry with OTLP exporter to the Datadog agent.
+/// The Datadog agent sidecar listens on localhost:4317 for OTLP gRPC.
+fn init_opentelemetry() -> SdkTracerProvider {
+ let exporter = opentelemetry_otlp::SpanExporter::builder()
+ .with_tonic()
+ .with_endpoint(OTEL_EXPORTER_OTLP_ENDPOINT)
+ .build()
+ .expect("failed to create OTLP span exporter");
+
+ // Get service name from DD_SERVICE or OTEL_SERVICE_NAME
+ let service_name =
+ std::env::var("DD_SERVICE").unwrap_or_else(|_| "unknown-service".to_string());
+
+ // Get environment from DD_ENV
+ let env = std::env::var("DD_ENV").unwrap_or_else(|_| "unknown".to_string());
+
+ let resource = opentelemetry_sdk::Resource::builder()
+ .with_service_name(service_name)
+ .with_attribute(opentelemetry::KeyValue::new("deployment.environment", env))
+ .build();
+
+ SdkTracerProvider::builder()
+ .with_batch_exporter(exporter)
+ .with_resource(resource)
+ .build()
+}
+
/// builder struct for modifying the local environment options
pub struct LocalOptionsBuilder {
prev: MacroEntrypoint,