Skip to content

ddsketch from histogram seems inaccurate #24365

@tony-resendiz

Description

@tony-resendiz

A note for the community

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Problem

hello, not sure if this is a bug or the intended behavior so i apologize if this is categorized incorrectly.

this issue is related to this discussion. the tl;dr is that when i record histograms of value 1 i see those averages around ~1.5 in datadog. it seems a result of this code where the dd sketch is built from bucket boundaries.

id like to propose updating the sketch sum, count, and avg fields from the histogram sum and count fields and would be happy to make a PR.

thanks for your time.

Configuration

[log_schema]
level_key = "status"
level = "info"

[api]
enabled = true
address = "0.0.0.0:8787"
playground = false

[sources.opentelemetry]
type = "opentelemetry"
grpc.address = "0.0.0.0:4317"
http.address = "0.0.0.0:4318"

[sinks.datadog_metrics_sink]
type = "datadog_metrics"
inputs = ["opentelemetry.metrics"]
default_api_key = "${DD_API_KEY}"
endpoint = "https://metrics.agent.datadoghq.com"

Version

0.51.1

Debug Output


Example Data

vector tap histogram event (sum = 2, count = 2, avg should be 1)

{
  "name": "test.default.vector.histogram",
  "tags": {
    "resource.service.name": "unknown_service",
    "resource.telemetry.sdk.language": "python",
    "resource.telemetry.sdk.name": "opentelemetry",
    "resource.telemetry.sdk.version": "1.38.0",
    "scope.name": "my-meter"
  },
  "timestamp": "2025-11-17T19:05:45.509186114Z",
  "kind": "incremental",
  "aggregated_histogram": {
    "buckets": [
      {
        "upper_limit": 0.0,
        "count": 0
      },
      {
        "upper_limit": 5.0,
        "count": 2
      },
      {
        "upper_limit": 10.0,
        "count": 0
      },
      {
        "upper_limit": 25.0,
        "count": 0
      },
      {
        "upper_limit": 50.0,
        "count": 0
      },
      {
        "upper_limit": 75.0,
        "count": 0
      },
      {
        "upper_limit": 100.0,
        "count": 0
      },
      {
        "upper_limit": 250.0,
        "count": 0
      },
      {
        "upper_limit": 500.0,
        "count": 0
      },
      {
        "upper_limit": 750.0,
        "count": 0
      },
      {
        "upper_limit": 1000.0,
        "count": 0
      },
      {
        "upper_limit": 2500.0,
        "count": 0
      },
      {
        "upper_limit": 5000.0,
        "count": 0
      },
      {
        "upper_limit": 7500.0,
        "count": 0
      },
      {
        "upper_limit": 10000.0,
        "count": 0
      },
      {
        "upper_limit": "inf",
        "count": 0
      }
    ],
    "count": 2,
    "sum": 2.0
  }
}

instead of avg=1 i see a dd-sketch request like this:

[22/Nov/2025 00:49:53] "POST /api/beta/sketches HTTP/1.1" 200 -

==== /api/beta/sketches ====
Sketch[0] metric=test.default.vector.histogram
  host=''
  tags=['resource.service.name:unknown_service', 'resource.telemetry.sdk.language:python', 'resource.telemetry.sdk.name:opentelemetry', 'resource.telemetry.sdk.version:1.38.0', 'scope.name:my-meter']
    dogsketch[0]: ts=1763772591, cnt=2, sum=2.5351459064147286, avg=1.2675729532073643, min=0.0, max=2.5351459064147286, k_len=2, n_len=2

Additional Context

No response

References

#24282

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugA code related bug.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions