Skip to content

feat(codecs): support encoding native Vector metrics in OTLP serializer#25738

Merged
petere-datadog merged 28 commits into
masterfrom
peter.ehik/OPA-5715/implement-otlp-metric-encoder
Jul 21, 2026
Merged

feat(codecs): support encoding native Vector metrics in OTLP serializer#25738
petere-datadog merged 28 commits into
masterfrom
peter.ehik/OPA-5715/implement-otlp-metric-encoder

Conversation

@petere-datadog

@petere-datadog petere-datadog commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Support encoding native Vector metrics in OTLP
  • This means you can now use otel destination with metrics inputs i.e. any metrics pipeline can sink to otel

Vector configuration

How did you test this PR?

Tested using this config:

sources:
  dd_agent:
    type: datadog_agent
    address: 0.0.0.0:8283
    multiple_outputs: true
    disable_logs: true
    disable_traces: true

transforms:
  filter_transform:
    type: filter
    inputs:
      - dd_agent.metrics
    condition:
      type: "vrl"
      source: '.type != "agent dd sketch"'

sinks:
  file_metrics:
    type: file
    inputs:
      - filter_transform
    path: /Users/peter.ehikhuemen/go/src/github.com/DataDog/vectordotdev/vector/tmp/dd-agent-metrics.log
    encoding:
      codec: json

  otlp_metrics:
    type: opentelemetry
    inputs:
      - filter_transform
    protocol:
      type: http
      uri: http://localhost:9090/api/v1/otlp/v1/metrics
      method: post
      encoding:
        codec: otlp
      request:
        headers:
          content-type: application/x-protobuf

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Some CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • make fmt
      • make check-clippy (if there are failures it's possible some of them can be fixed with make clippy-fix)
      • make test
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run make build-licenses to regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.

Adds metric -> OTLP conversion to the OTLP codec's serializer, covering
Counter, Gauge, AggregatedHistogram, and AggregatedSummary values via
direct prost encoding. Unsupported metric types (Set, Distribution,
Sketch) return an error naming the variant. The metric -> OTLP -> metric
round trip is deterministic; the reverse direction remains lossy by
design (e.g. ExponentialHistogram flattens to AggregatedHistogram).
@petere-datadog
petere-datadog requested a review from a team as a code owner July 1, 2026 21:49
@datadog-vectordotdev

datadog-vectordotdev Bot commented Jul 1, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2dd3804 | Docs | Give us feedback!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e9b90ea1a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
…P metric encoder

Fold the metric namespace into the OTLP metric name (joined with `.`) so
namespaced series such as `vector.requests` and `app.requests` keep distinct
OTLP identities instead of collapsing to `requests`.

Reject pre-epoch metric timestamps instead of casting a negative `i64`
nanosecond count into a far-future `u64`; the encoder now returns a
descriptive error so the event is dropped rather than emitted with a corrupt
timestamp.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fa8df168a1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/common.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d548decc43

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5ccc161e79

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/common.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7ee8b3dc9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2af64d1066

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@bruceg bruceg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks broadly appropriate but I am concerned about some of the inefficiencies caused by intermediate owned values (Vec, clones and structs).

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/codecs/src/encoding/format/otlp.rs Outdated
Comment thread lib/opentelemetry-proto/src/common.rs
Comment thread lib/opentelemetry-proto/src/common.rs Outdated
Comment thread lib/opentelemetry-proto/src/common.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs
@bruceg bruceg added domain: codecs Anything related to Vector's codecs (encoding/decoding) domain: metrics Anything related to Vector's metrics events sink: opentelemetry Anything `opentelemetry` sink related domain: opentelemetry type: feature A value-adding code addition that introduce new functionality. labels Jul 8, 2026
@github-actions github-actions Bot removed the domain: codecs Anything related to Vector's codecs (encoding/decoding) label Jul 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc23a5351d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aec7ac7995

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs

@bruceg bruceg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The behavior and calculations look correct so I'm approving as such. There seems to be a lot of room for optimization that we should return to, though, in the form of excess temporaries and copies and repeat operations on the same data.

Comment thread lib/opentelemetry-proto/src/common.rs
Comment thread lib/codecs/src/encoding/format/otlp.rs
Comment thread lib/codecs/src/encoding/format/otlp.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c8be33058

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9bbbd8169

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d36187fc75

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7533cd5632

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated

@pront pront left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great overall.

I examined the lifecycle of an event from OTEL to Vector to OTEL. Original:

resource.attributes: service.name = "python-hist-summary"
scope:               name="py-hist-summary" version="1.0"
metric:              name="python.test.histogram"  unit="ms"
histogram:
  aggregationTemporality: 2
  dataPoint:
    attributes:      route = "/api"
    timeUnixNano:    1784658526721324800
    count:           10
    sum:             42.5
    explicitBounds:  [1, 5, 10]
    bucketCounts:    [2, 3, 4, 1]

Final:

{
  "resource":  { "service.name": "python-hist-summary" },
  "scope":     { "name": "py-hist-summary", "version": "1.0" },
  "metric":    { "name": "python.test.histogram", "unit": null },
  "histogram": {
    "aggregationTemporality": 2,
    "dataPoints": [{
      "attributes":     [ { "route": "/api" } ],
      "timeUnixNano":   "1784658526721324800",
      "count":          "10",
      "sum":            42.5,
      "explicitBounds": [1, 5, 10],
      "bucketCounts":   ["2", "3", "4", "1"]
    }]
  }
}

Note that unit (from name="python.test.histogram" unit="ms") is missing. I suspect if the original OTEL event had description that would also be missing. But preserving those isn't trivial and not a blocker for this PR.

Comment thread lib/codecs/src/encoding/format/otlp.rs Outdated
Comment thread lib/opentelemetry-proto/src/metrics.rs
Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
petere-datadog and others added 2 commits July 21, 2026 16:30
Throw error if event timestamp is somehow out of u64 range.

Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
add metric type to input types accepted by OtlpSerializer

Co-authored-by: Pavlos Rontidis <pavlos.rontidis@gmail.com>
@petere-datadog

Copy link
Copy Markdown
Contributor Author

This looks great overall.

I examined the lifecycle of an event from OTEL to Vector to OTEL. Original:

resource.attributes: service.name = "python-hist-summary"
scope:               name="py-hist-summary" version="1.0"
metric:              name="python.test.histogram"  unit="ms"
histogram:
  aggregationTemporality: 2
  dataPoint:
    attributes:      route = "/api"
    timeUnixNano:    1784658526721324800
    count:           10
    sum:             42.5
    explicitBounds:  [1, 5, 10]
    bucketCounts:    [2, 3, 4, 1]

Final:

{
  "resource":  { "service.name": "python-hist-summary" },
  "scope":     { "name": "py-hist-summary", "version": "1.0" },
  "metric":    { "name": "python.test.histogram", "unit": null },
  "histogram": {
    "aggregationTemporality": 2,
    "dataPoints": [{
      "attributes":     [ { "route": "/api" } ],
      "timeUnixNano":   "1784658526721324800",
      "count":          "10",
      "sum":            42.5,
      "explicitBounds": [1, 5, 10],
      "bucketCounts":   ["2", "3", "4", "1"]
    }]
  }
}

Note that unit (from name="python.test.histogram" unit="ms") is missing. I suspect if the original OTEL event had description that would also be missing. But preserving those isn't trivial and not a blocker for this PR.

@pront main reason we can't preserve those is they're not currently captured in a MetricEvent, we would have to update that struct or do something interesting with tags

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 15c22f6c36

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lib/opentelemetry-proto/src/metrics.rs Outdated
@petere-datadog
petere-datadog enabled auto-merge July 21, 2026 20:43
@petere-datadog
petere-datadog added this pull request to the merge queue Jul 21, 2026
Merged via the queue into master with commit b2bf6fc Jul 21, 2026
61 checks passed
@petere-datadog
petere-datadog deleted the peter.ehik/OPA-5715/implement-otlp-metric-encoder branch July 21, 2026 21:32
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

domain: metrics Anything related to Vector's metrics events domain: opentelemetry sink: opentelemetry Anything `opentelemetry` sink related type: feature A value-adding code addition that introduce new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants