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

[processor/transform] unable to parse OTTL statement #27012

Closed
nickv2002 opened this issue Sep 20, 2023 · 3 comments
Closed

[processor/transform] unable to parse OTTL statement #27012

nickv2002 opened this issue Sep 20, 2023 · 3 comments
Labels
bug Something isn't working needs triage New item requiring triage processor/transform Transform processor

Comments

@nickv2002
Copy link
Contributor

nickv2002 commented Sep 20, 2023

Component(s)

processor/transform

Description

I'm trying to follow the example from here to add metric labels for Prometheus. It suggests using the transform processor like so in order to copy the most common resource attributes into metric labels:

processor:
  transform:
    metric_statements:
      - context: metric
        statements:
        - set(attributes["namespace"], resource.attributes["k8s_namespace_name"])
        - set(attributes["container"], resource.attributes["k8s.container.name"])
        - set(attributes["pod"], resource.attributes["k8s.pod.name"])
        - set(attributes["cluster"], resource.attributes["k8s.cluster.name"])

Given that example I've simplified my collector config down to this simplified version:.

processors:
  transform:
    metric_statements:
      - context: metric
        statements:
          - set(attributes["k8s_namespace_name"], resource.attributes["k8s_namespace_name"])
  resource:
    attributes:
      - key: environment_name
        value: dev
        action: insert
exporters:
  otlphttp:
    endpoint: <Omitted>
service:
  extensions: [health_check]
  pipelines:
    metrics:
      receivers: [otlp]
      processors: [resource, transform, batch]
      exporters: [otlphttp]

Unfortunately, with this configuration, the collector fails to start and complains with the following message:

Error: invalid configuration: processors::transform: unable to parse OTTL statement "set(attributes["k8s_namespace_name"], resource.attributes["k8s_namespace_name"])": error while parsing arguments for call to "set": invalid argument at position 0: invalid metric path expression [{attributes [{0xc002ad2250 }]}]2023/09/20 00:43:53 collector server run finished with error: invalid configuration: processors::transform: unable to parse OTTL statement "set(attributes["k8s_namespace_name"], resource.attributes["k8s_namespace_name"])": error while parsing arguments for call to "set": invalid argument at position 0: invalid metric path expression [{attributes [{0xc002ad2250 }]}]

Collector version

0.85.0

Environment

docker image: otel/opentelemetry-collector-contrib:0.85.0

@nickv2002 nickv2002 added bug Something isn't working needs triage New item requiring triage labels Sep 20, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@github-actions github-actions bot added the processor/transform Transform processor label Sep 20, 2023
@nickv2002 nickv2002 changed the title [transform/set.attributes] unable to parse OTTL statement [processor/transform] unable to parse OTTL statement Sep 20, 2023
@TylerHelmuth
Copy link
Member

The metric context does have have attributes because metrics don't have attributes. Try the datapoint context.

@nickv2002
Copy link
Contributor Author

The metric context does not have attributes because metrics don't have attributes. Try the datapoint context.

@TylerHelmuth thanks for that tip. I've got it working for several attributes that are now showing up with proper labels in Prometheus/Grafana. Here's an excerpt of my working config (for other's potential ref):

processors:
  transform:
    trace_statements:
      - context: span
        statements:
        - set(resource.attributes["cluster"], "dev")
    metric_statements:
      - context: datapoint
        statements:
        - set(attributes["k8s_namespace"], resource.attributes["k8s.namespace.name"])
        - set(attributes["k8s_container"], resource.attributes["k8s.container.name"])
        - set(attributes["k8s_deployment"], resource.attributes["k8s.deployment.name"])
        - set(attributes["k8s_pod"], resource.attributes["k8s.pod.name"])
        - set(attributes["telemetry_sdk_language"], resource.attributes["telemetry.sdk.language"])
        - set(attributes["cluster"], "dev")

Seems like the documentation should be updated here and here

I will see if I can make a quick PR for that.

TylerHelmuth pushed a commit that referenced this issue Sep 21, 2023
**Description:** 
- Fixing documentation for incorrect transform context.
- Correcting `resource.attributes["k8s_namespace_name"` to be correct
`.` separated name.
- Removing `resource.attributes["k8s.cluster.name"]` as it's not an
available attribute.  

**Link to tracking Issue:**

#27012 (comment)

**Testing:** 
Works in my own otel-collector.

**Documentation:** 
All documentation updates here.
harishbohara11 pushed a commit to harishbohara11/opentelemetry-collector-contrib that referenced this issue Sep 21, 2023
)

**Description:** 
- Fixing documentation for incorrect transform context.
- Correcting `resource.attributes["k8s_namespace_name"` to be correct
`.` separated name.
- Removing `resource.attributes["k8s.cluster.name"]` as it's not an
available attribute.  

**Link to tracking Issue:**

open-telemetry#27012 (comment)

**Testing:** 
Works in my own otel-collector.

**Documentation:** 
All documentation updates here.
jorgeancal pushed a commit to jorgeancal/opentelemetry-collector-contrib that referenced this issue Oct 9, 2023
)

**Description:** 
- Fixing documentation for incorrect transform context.
- Correcting `resource.attributes["k8s_namespace_name"` to be correct
`.` separated name.
- Removing `resource.attributes["k8s.cluster.name"]` as it's not an
available attribute.  

**Link to tracking Issue:**

open-telemetry#27012 (comment)

**Testing:** 
Works in my own otel-collector.

**Documentation:** 
All documentation updates here.
jmsnll pushed a commit to jmsnll/opentelemetry-collector-contrib that referenced this issue Nov 12, 2023
)

**Description:** 
- Fixing documentation for incorrect transform context.
- Correcting `resource.attributes["k8s_namespace_name"` to be correct
`.` separated name.
- Removing `resource.attributes["k8s.cluster.name"]` as it's not an
available attribute.  

**Link to tracking Issue:**

open-telemetry#27012 (comment)

**Testing:** 
Works in my own otel-collector.

**Documentation:** 
All documentation updates here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage New item requiring triage processor/transform Transform processor
Projects
None yet
Development

No branches or pull requests

2 participants