Skip to content

Define MCPTelemetryConfig API Types #4262

Closed

Description

@ChrisJBurns

Description

Create the MCPTelemetryConfig CRD type definitions using a nested structure with openTelemetry and prometheus sub-objects, as specified in RFC THV-0023.

Why nested instead of flat?

The original implementation used inline embedding of telemetry.Config which exposed CLI-only fields (environmentVariables) and per-server fields (serviceName) in the CRD spec. The RFC specifies a nested structure that:

  • Groups OTLP settings under spec.openTelemetry (endpoint, headers, tracing, metrics)
  • Groups Prometheus settings under spec.prometheus
  • Excludes serviceName (per-server, set via MCPTelemetryConfigReference)
  • Excludes environmentVariables and customAttributes (CLI-only)
  • Uses resourceAttributes instead of customAttributes for OTel resource attributes

Target Structure

apiVersion: toolhive.stacklok.dev/v1alpha1
kind: MCPTelemetryConfig
metadata:
  name: production-telemetry
  namespace: mcp-platform
spec:
  openTelemetry:
    enabled: true
    endpoint: otel-collector.monitoring.svc.cluster.local:4318
    insecure: false
    sensitiveHeaders:
      - name: Authorization
        secretKeyRef:
          name: otel-auth-secret
          key: bearer-token
      - name: X-API-Key
        secretKeyRef:
          name: otel-secret
          key: api-key
    resourceAttributes:
      service.namespace: toolhive
      deployment.environment: production
    metrics:
      enabled: true
    tracing:
      enabled: true
      samplingRate: "0.1"
    useLegacyAttributes: true
  prometheus:
    enabled: true
status:
  observedGeneration: 1
  configHash: "sha256:..."
  referencingWorkloads:
    - kind: MCPServer
      name: server-a
  conditions:
    - type: Valid
      status: "True"

Go Types

type MCPTelemetryConfigSpec struct {
    OpenTelemetry *MCPTelemetryOTelConfig `json:"openTelemetry,omitempty"`
    Prometheus    *PrometheusConfig        `json:"prometheus,omitempty"`
}

type MCPTelemetryOTelConfig struct {
    Enabled            bool                        `json:"enabled,omitempty"`
    Endpoint           string                      `json:"endpoint,omitempty"`
    Insecure           bool                        `json:"insecure,omitempty"`
    Headers            map[string]string            `json:"headers,omitempty"`
    SensitiveHeaders   []SensitiveHeader            `json:"sensitiveHeaders,omitempty"`
    ResourceAttributes map[string]string            `json:"resourceAttributes,omitempty"`
    Metrics            *OpenTelemetryMetricsConfig  `json:"metrics,omitempty"`
    Tracing            *OpenTelemetryTracingConfig  `json:"tracing,omitempty"`
    UseLegacyAttributes bool                        `json:"useLegacyAttributes"`
}

type MCPTelemetryConfigStatus struct {
    Conditions           []metav1.Condition  `json:"conditions,omitempty"`
    ObservedGeneration   int64               `json:"observedGeneration,omitempty"`
    ConfigHash           string              `json:"configHash,omitempty"`
    ReferencingWorkloads []WorkloadReference  `json:"referencingWorkloads,omitempty"`
}

// WorkloadReference is shared across CRDs (defined in mcpoidcconfig_types.go)
type WorkloadReference struct {
    Kind string `json:"kind"` // MCPServer, VirtualMCPServer, MCPRemoteProxy
    Name string `json:"name"`
}

Key Design Decisions

  • Headers is map[string]string for non-sensitive headers (e.g., X-Custom-Tag: value). Credential headers (bearer tokens, API keys) should use sensitiveHeaders with SecretKeyRef instead.
  • SensitiveHeaders uses SecretKeyRef for credential headers (no inline secrets)
  • ResourceAttributes replaces customAttributes — maps to telemetry.Config.CustomAttributes at runtime
  • ServiceName excluded from shared config — it is per-server via MCPTelemetryConfigReference
  • WorkloadReference is a shared type (defined in mcpoidcconfig_types.go) with Kind + Name — namespace is implicit since cross-namespace refs are not supported
  • Conversion from CRD nested types to flat telemetry.Config is handled by spectoconfig.NormalizeMCPTelemetryConfig

Phase 2 Fields (not yet implemented)

These RFC fields require runtime support and will be added in follow-up PRs:

  • spec.openTelemetry.protocol (http/grpc) — needs gRPC exporter support
  • spec.openTelemetry.metrics.exportInterval — needs sdkmetric.WithInterval()
  • spec.openTelemetry.tracing.propagators — needs dynamic propagator factory
  • spec.prometheus.path — hardcoded to /metrics
  • spec.prometheus.port — shares transport port

Acceptance Criteria

  • MCPTelemetryConfigSpec uses nested openTelemetry/prometheus structure matching RFC THV-0023
  • Headers is map[string]string
  • SensitiveHeaders uses SecretKeyRef for credential headers
  • ResourceAttributes field for shared OTel resource attributes
  • ServiceName excluded from shared config (per-server field)
  • ReferencingWorkloads uses shared WorkloadReference type (Kind + Name)
  • Conversion layer (spectoconfig.NormalizeMCPTelemetryConfig) maps nested CRD to flat telemetry.Config
  • task operator-generate and task operator-manifests succeed
  • Unit tests verify type structure and conversion correctness
  • Tests pass (task test)

Activity

  1. added
    enhancement
    kubernetes
    on Mar 19, 2026
  2. added 3 commits that reference this issue on Apr 1, 2026
    be4ab03
    7eb77c8
    b58a4e4
  3. added a commit that references this issue on Apr 2, 2026
    a78d9bf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementkubernetesoperatortelemetry

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions