solo-io / envoy-gloo

Apache License 2.0
25 stars 14 forks source link

Set opentelemetry span name in transformation filter #368

Closed ashishb-solo closed 1 month ago

ashishb-solo commented 1 month ago

This pull request adds the ability to set the span name in the transformation filter.

We add a new field in the transformation template to allow setting modifying the span. The new field currently only accepts the span name as a field, but attributes/baggage/other data could also be added as fields to be modified here as well.

If route.decorator.operation is set, we should not update the field in this filter - we intend for the operation field to take precedence over this value, which is set at the virtual host level and intended to be used as a default instead.

Here is an envoy configuration for testing - note the presence of route.decorator.operation, and how uncommenting it causes Envoy to use that field as the span name instead of the hostname.

# required for toggling runtime reloadable features
layered_runtime:
  layers:
  - name: admin
    admin_layer: {}

# taken from https://www.envoyproxy.io/docs/envoy/latest/start/quick-start/configuration-static
# or view-source:https://www.envoyproxy.io/docs/envoy/latest/_downloads/92dcb9714fb6bc288d042029b34c0de4/envoy-demo.yaml
admin:
  address:
    socket_address: { address: 127.0.0.1, port_value: 9901 }

static_resources:

  listeners:
  - name: listener_0
    address:
      socket_address:
        address: 0.0.0.0
        port_value: 10000
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          stat_prefix: ingress_http
          generate_request_id: true
          access_log:
          - name: envoy.access_loggers.stdout
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.access_loggers.stream.v3.StdoutAccessLog
              # log_format:
              #   text_format_source:
              #     inline_string: "test\n"
          tracing:
            provider:
              name: envoy.tracers.opentelemetry
              typed_config:
                "@type": type.googleapis.com/envoy.config.trace.v3.OpenTelemetryConfig
                grpc_service:
                  envoy_grpc:
                    cluster_name: opentelemetry_collector
                  timeout: 0.250s
                service_name: gateway-proxy
          codec_type: AUTO
          http_filters:
          - name: io.solo.transformation
            typed_config:
              '@type': type.googleapis.com/envoy.api.v2.filter.http.FilterTransformations
          # - name: io.solo.filters.http.span_decorators
          #   typed_config:
          #     "@type": type.googleapis.com/envoy.config.filter.http.span_decorators.v3.SpanDecorators
          #     # span_name: "HTTP CONNECTION MANAGER"
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
          route_config:
            name: local_route
            virtual_hosts:
            - name: local_service
              domains: ["*"]
              typed_per_filter_config:
                io.solo.transformation:
                  '@type': type.googleapis.com/envoy.api.v2.filter.http.RouteTransformations
                  transformations:
                    - request_match:
                        request_transformation:
                          transformation_template:
                            span_transformer:
                              name:
                                text: '{{ header("host") }}'
                                # text: '{{clusterMetadata("io.solo.hostname")}}'
                            headers:
                              test_header:
                                text: TEST_VALUE
              #   io.solo.filters.http.span_decorators:
              #     "@type": type.googleapis.com/envoy.config.filter.http.span_decorators.v3.SpanDecorators
              #     span_name: "VIRTUAL HOST"
              routes:
              - match:
                  prefix: "/"
                route:
                  cluster: echo-server
                # if these fields are uncommented, they will override the value set in the transformation template
                # decorator:
                #   operation: "HEY_EVERYONE_THIS_IS_A_CUSTOM_SPAN_NAME!!!"

  clusters:
  - name: opentelemetry_collector
    type: STRICT_DNS
    connect_timeout: 5s
    http2_protocol_options: {}
    dns_lookup_family: V4_ONLY
    metadata: {}
    load_assignment:
      cluster_name: opentelemetry_collector
      endpoints:
        - lb_endpoints:
            - endpoint:
                address:
                  socket_address:
                    address: 127.0.0.1
                    port_value: 4317
                health_check_config:
                  hostname: otel-collector
                hostname: otel-collector
              metadata:
                filter_metadata:
                  envoy.transport_socket_match:
                    otel-collector;otel-collector:4317: true
    typed_extension_protocol_options:
      envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
        '@type': >-
          type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
        explicit_http_config:
          http2_protocol_options: {}
  - name: echo-server
    type: STATIC
    load_assignment:
      cluster_name: echo-server
      endpoints:
        - lb_endpoints:
            - endpoint:
                address:
                  socket_address:
                    address: 127.0.0.1
                    port_value: 11100
  - name: service_envoyproxy_io
    type: LOGICAL_DNS
    # Comment out the following line to test on v6 networks
    dns_lookup_family: V4_ONLY
    load_assignment:
      cluster_name: service_envoyproxy_io
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: www.envoyproxy.io
                port_value: 443
    transport_socket:
      name: envoy.transport_sockets.tls
      typed_config:
        "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
        sni: www.envoyproxy.io
solo-changelog-bot[bot] commented 1 month ago

Issues linked to changelog: https://github.com/solo-io/gloo/issues/9848