Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set opentelemetry span name in transformation filter #368

Merged
merged 11 commits into from
Oct 1, 2024

Conversation

ashishb-solo
Copy link
Contributor

@ashishb-solo ashishb-solo commented Sep 28, 2024

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
Copy link

Issues linked to changelog:
solo-io/gloo#9848

@ashishb-solo ashishb-solo changed the title Opentelemetry set operation patch Set opentelemetry span name in transformation filter Oct 1, 2024
if (callbacks.route()
&& callbacks.route()->decorator()
&& !callbacks.route()->decorator()->getOperation().empty()) {
callbacks.activeSpan().setOperation(callbacks.route()->decorator()->getOperation());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO delete this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was refactored in 3d7463c


InjaTransformer transformer(transformation, rng_, google::protobuf::BoolValue(), tls_);
std::unique_ptr<Tracing::MockSpan> mock_span = std::make_unique<Tracing::MockSpan>();
const std::unique_ptr<Router::MockDecorator> mock_decorator = std::make_unique<NiceMock<Router::MockDecorator>>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there simpler ways to set up these mocks?

This is the default value that is set from the HCM - we do not need to write it
a second time.
Copy link
Collaborator

@nfuden nfuden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it out on my local as well. I like it!

@soloio-bulldozer soloio-bulldozer bot merged commit 9c14c3a into release-v1.30 Oct 1, 2024
4 checks passed
@soloio-bulldozer soloio-bulldozer bot deleted the opentelemetry-set-operation-patch branch October 1, 2024 17:26
ashishb-solo added a commit that referenced this pull request Oct 1, 2024
* Add setOperation patch

* Add changelog

* Transformation initial implementation

Should work but does not seem to at the moment

* Implement unit test for setting span name

* Update changelog

* Remove extra entry from changelog

* Do not override route.decorator.operation

* Add test for null route in callbacks

* Remove redundant call to setOperation

This is the default value that is set from the HCM - we do not need to write it
a second time.
soloio-bulldozer bot pushed a commit that referenced this pull request Oct 1, 2024
…368) (#369)

* Set opentelemetry span name in transformation filter (#368)

* Add setOperation patch

* Add changelog

* Transformation initial implementation

Should work but does not seem to at the moment

* Implement unit test for setting span name

* Update changelog

* Remove extra entry from changelog

* Do not override route.decorator.operation

* Add test for null route in callbacks

* Remove redundant call to setOperation

This is the default value that is set from the HCM - we do not need to write it
a second time.

* Move changelog

* Move changelog... again!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants