Hmm, the user is asking for an OpenTelemetry-first stack design with specific technical components: schema alignment, baggage rules, sampling gates, and service maps. This is a focused, expert-level request about observability infrastructure.
I need to structure this as a practical implementation blueprint rather than just conceptual advice. The user likely wants actionable steps, tool recommendations, and code examples. Since they mentioned "stack," I should cover end-to-end: from instrumentation to visualization.
First, I should emphasize the OpenTelemetry Collector as the central nervous system—it handles all four requested components. For schema alignment, I'll highlight semantic conventions and transformation processors. Baggage rules belong in the Collector's baggage processor. Sampling gates need both tail and head sampling strategies. Service maps require combining topology data with traces.
I should warn about common pitfalls like baggage bloat and sampling misconfiguration. The response must balance depth with clarity, avoiding vendor lock-in while mentioning popular tools like Tempo, Jaeger, and Grafana. Code snippets for Collector config will make it concrete.
The user might be an SRE or platform engineer building a new observability stack, so I'll assume they need both conceptual rationale and implementation details. I'll end with a phased rollout plan—this isn't a trivial weekend project.
Excellent. Building an OpenTelemetry-first stack means making OpenTelemetry (OTel) the central, canonical format for all telemetry, and building your entire observability pipeline around its standards and APIs. This eliminates format conversion hell and provides a single source of truth.
Here is a comprehensive blueprint for your stack, designed to implement your four key pillars: Schema Alignment, Baggage Rules, Sampling Gates, and Service Maps.
Core Philosophy: The Collector as the Orchestrator
The OpenTelemetry Collector is not just a receiver/exporter; it's the brain of your operations. All logic for your four pillars will be configured here.
1. Schema Alignment: Enforcing Semantic Conventions
Goal: Ensure all services emit data with consistent, meaningful attribute names and structures, making correlation and analysis reliable.
Implementation:
- Standard: Enforce the OpenTelemetry Semantic Conventions (for HTTP, DB, messaging, etc.).
- Tool: Use the Collector's
transform processor or resource processor.
- Actionable Steps:
- Define Your "Golden Signals" Attributes: Agree on standard names for key business/technical context (e.g.,
service.version, deployment.environment, team, datacenter).
- Instrumentation Libraries: Ensure your application libraries (e.g.,
opentelemetry-java-instrumentation, opentelemetry-python-auto-instrumentation) are up-to-date and configured to use the latest semantic conventions.
- Collector Transformation Pipeline: Normalize and standardize on the back-end.
# Example Collector config snippet (YAML)
processors:
# 1. Resource processor: Set standard, static resource attributes.
resource:
attributes:
- key: deployment.environment
value: production
action: insert
- key: service.namespace
value: my-company.ecommerce
action: insert
# 2. Transform processor: Rename non-standard attributes from legacy apps.
transform:
log_statements:
- mode: insert
statements:
- set(attributes["http.method"], attributes["http_method"]) # Rename
- delete_key(attributes["legacy_tag"])
- Validate: Use the Collector's
filelog receiver to ingest application logs and the logging exporter (to stdout) during rollout to audit attribute shapes.
2. Baggage Rules: Propagating Context with Control
Goal: Propagate key-value pairs across service boundaries intentionally, avoiding baggage bloat while enabling critical cross-cutting concerns (tenant ID, auth context, debug flags).
Implementation:
- Standard: Use W3C Baggage header format (built into OTel propagators).
- Tool: Collector's
baggage processor and careful propagator configuration.
- Actionable Steps:
- Define a "Baggage Schema": Document allowed baggage keys, value formats, and their owners.
x-sdk-version: (Read-only, injected by SDKs)
tenant.id: (Set by ingress/gateway)
auth.user.id: (Set by auth service)
debug.flag: (Set by support tooling, transient)
circuit.breaker.state: (Potentially set by resilience layer)
- Configure Baggage Propagation in Collector:
# Collector config
extensions:
# This enables the OTLP receiver to accept/send baggage.
health_check: {}
receivers:
otlp:
protocols:
grpc:
http:
processors:
# The key processor. Define ALLOW and DENY lists.
baggage:
# ALLOW only specific keys to be propagated *outbound* from this service.
# This prevents internal-only context from leaking.
include_allowed_keys:
- tenant.id
- user.id
- debug.flag
- traceparent # Essential, but usually managed by propagator
# Optionally, STRIP baggage on inbound to a trust boundary.
# strip_all_unknown_keys: true # (Use with caution)
exporters:
otlp:
endpoint: "tempo:4317"
# The baggage processor ensures only allowed keys are sent.
service:
pipelines:
traces:
receivers: [otlp]
processors: [baggage, ...]
exporters: [otlp]
- Application Configuration: Your applications should not manually set
baggage.set(...) in most cases. The Collector should be the authoritative baggage filter. Use the OTel SDK's propagator configuration to ensure the standard W3CBaggagePropagator is active.
3. Sampling Gates: Intelligent, Policy-Driven Sampling
Goal: Move beyond simple random or fixed-rate sampling. Make sampling decisions based on trace content (e.g., error status, high latency, specific baggage, service depth).
Implementation:
- Tools: Collector's
tail_sampling processor (for decisions based on the full trace) and probabilistic_sampler (for head sampling).
- Actionable Steps:
- Define Sampling Policies: What traces must be sampled?
- All traces with an error (
status.is_ok = false).
- All traces with latency > 5s.
- All traces with baggage
tenant.id = "premium".
- A percentage (e.g., 1%) of all other traces.
- Configure
tail_sampling in Collector: This is where your "gates" live.
processors:
tail_sampling:
decision_wait: 10s # Wait to see the full trace
num_traces: 1000 # Buffer size
expected_new_traces_per_sec: 100
policies:
# Policy 1: Always sample if there's an error.
- name: error-policy
type: status_code
status_code:
- ERROR
# Policy 2: Sample high-latency traces.
- name: slow-trace-policy
type: latency
latency:
threshold_ms: 5000
# Policy 3: Sample based on baggage.
- name: premium-tenant-policy
type: string_attribute
string_attribute:
key: baggage.tenant.id
values: ["premium"]
# Policy 4: Fallback probabilistic sampler.
- name: fallback-random
type: probabilistic
probabilistic:
sampling_percentage: 1.0 # 1%
- Combine with Head Sampling: Use
probabilistic_sampler before tail_sampling for very high-volume services to reduce load on the Collector's tail sampler buffer. Order matters: receiver -> probabilistic_sampler -> tail_sampling -> exporter.
4. Service Maps: From Traces to a Living Topology
Goal: Automatically generate, update, and visualize your microservices architecture and their dependencies, with health overlay.
Implementation:
- Data Source: Traces are the single source of truth for dynamic service-to-service calls.
- Tools:
- Storage: A trace storage optimized for topology queries (e.g., Grafana Tempo, Jaeger).
- Visualization & Computation:
- Grafana + Tempo Plugin: The most integrated OTel-native option. Its Service Map panel uses trace data to build graph nodes (services) and edges (calls), with color/size based on metrics (error rate, latency).
- Arize AI's Phoenix or Elastic APM: Also offer strong service maps.
- DIY: Query your trace store (e.g., using Tempo's metrics generator or Jaeger's gRPC API) to build the graph yourself.
- Actionable Steps:
- Ensure Complete Service Identity: Your schema alignment (Step 1) must produce a unique, consistent
service.name and service.version for every service. This is the node ID.
- Configure Trace Storage: Use a system that supports metrics generated from traces (Tempo does this via its metrics generator). This is crucial for coloring service map edges by error rate/latency.
- Build the Map in Grafana:
- Create a dashboard.
- Add a "Tempo Service Map" panel.
- Configure the data source (Tempo).
- Set the "Service Name" field to
{$service.name} (a variable).
- Use the "Layout" options (e.g.,
Dagre for hierarchical, Force for organic).
- Overlay Health: The panel can automatically color nodes/edges based on
span.status.code and span.duration.
- Correlate with Metrics: Link the service map to your Prometheus/Jaeger metrics data in Grafana. Clicking a node can show its CPU/memory history.
The Complete OpenTelemetry-First Stack Diagram
[Your Instrumented Services]
| (OTLP over gRPC/HTTP)
v
[OpenTelemetry Collector Cluster] <--- [Configuration-as-Code (collector-config.yaml)]
| (Processors: resource, transform, baggage, tail_sampling)
| (Logic for all 4 pillars lives here)
v
[Trace Storage] (Grafana Tempo) <-- Metrics generated from traces
|
v
[Visualization] (Grafana)
| - Service Map Panel
| - Traces Explorer
| - Metrics correlated
v
[Alerting] (Grafana / Prometheus Alertmanager)
| - Alert on tail sampling policy hits (e.g., "error-policy rate high")
| - Alert on service map node failures (via metrics)
Critical Success Factors & Pitfalls
- Configuration Management: Your
collector-config.yaml is critical infrastructure. Store it in Git, use a config manager (e.g., Reloader for K8s), and test changes with the otelcol CLI.
- Start Simple: Begin with
probabilistic_sampling (e.g., 10%) and resource processor. Then add tail_sampling policies one by one.
- Baggage Hygiene: STRICT
include_allowed_keys in the baggage processor is non-negotiable. Unchecked baggage is a memory/performance disaster.
- Service Map Accuracy: It's only as good as your
service.name consistency. Use the resource processor to canonicalize names from different teams (e.g., map checkout-svc, checkout-service to checkout).
- Cost Control: Tail sampling buffers traces in memory. Set
decision_wait and num_traces based on your trace volume and latency SLOs to avoid OOM.
Phased Rollout Plan
- Phase 1 (Foundation): Instrument key services with OTel SDKs, set up Collector with
resource and probabilistic_sampler (10%), export to Tempo. Verify traces in Grafana.
- Phase 2 (Alignment): Implement
transform processor to fix legacy attribute names. Establish the service.name standard.
- Phase 3 (Intelligent Sampling): Deploy
tail_sampling with your 2-3 most critical policies (errors, latency). Monitor the sampling_decision metrics.
- Phase 4 (Context Propagation): Define and implement baggage rules via the
baggage processor. Test with a dedicated "debug" policy.
- Phase 5 (Visualization & Ownership): Build the Service Map dashboard. Share it with teams. Set up alerts based on the map's health indicators.
By following this blueprint, you move from having traces to having a governed, actionable, and cost-controlled observability fabric built on the vendor-neutral standard of OpenTelemetry.