open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.96k stars 2.3k forks source link

Instrumentation scope not present in Metric stream #31028

Open cwegener opened 8 months ago

cwegener commented 8 months ago

Component(s)

receiver/sqlquery

What happened?

Description

The Instrumentation Scope is not being set to the expected value (i.e. otelcol/sqlqueryreceiver) in the Metric streams that are generated from the sqlqueryreceiver.

Steps to Reproduce

  1. Download otelcol-contrib v0.93.0 or earlier
  2. Run collector with the provided sample configuration
  3. Observe the Metrics stream produced on stdout

Expected Result

The Instrumentation Scope should show otelcol/sqlqueryreceiver

Actual Result

The Instrumentation Scope is empty

Collector version

v0.93.0

Environment information

Environment

OS: Ubuntu 22.04,

OpenTelemetry Collector configuration

receivers:
  sqlquery/test:
    driver: postgres
    collection_interval: 60s
    datasource: "postgres://user:password@/database?sslmode=disable"
    queries:
      - sql: |
          select now() as "timestamp", 1 as "metric"

        metrics:
          - metric_name: testmetric
            value_column: metric
            value_type: int
            data_type: gauge
            unit: "1"

exporters:
  logging:
    verbosity: detailed

service:
  pipelines:
    metrics:
      receivers:
        - sqlquery/test
      processors: []
      exporters:
        - logging

Log output

2024-02-05T17:55:10.631+1100    info    service@v0.93.0/telemetry.go:76 Setting up own telemetry...
2024-02-05T17:55:10.631+1100    info    service@v0.93.0/telemetry.go:146        Serving metrics {"address": ":8888", "level": "Basic"}
2024-02-05T17:55:10.631+1100    info    exporter@v0.93.0/exporter.go:275        Deprecated component. Will be removed in future releases.       {"kind": "exporter", "data_type": "metrics", "name": "logging"}
2024-02-05T17:55:10.632+1100    info    service@v0.93.0/service.go:139  Starting otelcol-contrib...     {"Version": "0.93.0", "NumCPU": 16}                                                                                                                    2024-02-05T17:55:10.632+1100    info    extensions/extensions.go:34     Starting extensions...                                                                                                                                                                 2024-02-05T17:55:10.632+1100    info    service@v0.93.0/service.go:165  Everything is ready. Begin running and processing data.
2024-02-05T17:55:11.641+1100    info    MetricsExporter {"kind": "exporter", "data_type": "metrics", "name": "logging", "resource metrics": 1, "metrics": 1, "data points": 1}
2024-02-05T17:55:11.641+1100    info    ResourceMetrics #0
Resource SchemaURL:
ScopeMetrics #0
ScopeMetrics SchemaURL:
InstrumentationScope
Metric #0
Descriptor:
     -> Name: testmetric
     -> Description:
     -> Unit: 1
     -> DataType: Gauge
NumberDataPoints #0
StartTimestamp: 1970-01-01 00:00:00 +0000 UTC
Timestamp: 2024-02-05 06:55:11.641453691 +0000 UTC
Value: 1
        {"kind": "exporter", "data_type": "metrics", "name": "logging"}
^C2024-02-05T17:55:13.613+1100  info    otelcol@v0.93.0/collector.go:258        Received signal from OS {"signal": "interrupt"}
2024-02-05T17:55:13.613+1100    info    service@v0.93.0/service.go:179  Starting shutdown...
2024-02-05T17:55:13.614+1100    info    extensions/extensions.go:59     Stopping extensions...
2024-02-05T17:55:13.614+1100    info    service@v0.93.0/service.go:193  Shutdown complete.

Additional context

No response

github-actions[bot] commented 8 months ago

Pinging code owners:

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

crobert-1 commented 7 months ago

Thanks for filing @cwegener, I agree this is a valid issue.

As far as solution, we'd want to set the scope name here: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/2047ee9c1146241b2e7770a077cd1ed13469eb64/internal/sqlquery/scraper.go#L86

A lot of internal logic of the sqlquery receiver was moved to a separate package so that multiple receivers can use it. Since multiple receivers may be calling the Scrape method, their scope name should be passed to the internal package as an internal config variable, without user configuration. This would allow users to know which receiver the metric is coming from, instead of a single default value.

github-actions[bot] commented 5 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

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

github-actions[bot] commented 3 months ago

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

Pinging code owners:

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