Skip to content
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0908994
feat: first version of metricsaslogs connector
kyo-ke Aug 16, 2025
398c37c
feat: update go.mod, go.sum
kyo-ke Aug 17, 2025
1976421
make goporto
kyo-ke Aug 17, 2025
ddaaf73
make addlicense
kyo-ke Aug 17, 2025
f1b4754
add changelog
kyo-ke Aug 17, 2025
88bccd1
update metadata + versions
kyo-ke Aug 17, 2025
6ccdfaa
update codeowner
kyo-ke Aug 17, 2025
1a95e3f
fix lint
kyo-ke Aug 19, 2025
b0b3efe
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 20, 2025
4051098
Merge branch 'main' of github.com:kyo-ke/opentelemetry-collector-cont…
kyo-ke Aug 20, 2025
376837f
update module
kyo-ke Aug 20, 2025
d846ebf
Merge branch 'metricsaslogsconnector' of github.com:kyo-ke/openteleme…
kyo-ke Aug 20, 2025
879490b
update tidylist
kyo-ke Aug 21, 2025
e22dd70
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 21, 2025
8c27372
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 21, 2025
828933e
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 22, 2025
3b49e67
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 24, 2025
d29f303
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 25, 2025
8913ef3
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 26, 2025
98f964f
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 27, 2025
a0e1f5f
update go mod
kyo-ke Aug 27, 2025
8010c5d
change alpha to development & make generate & make genlabels
kyo-ke Aug 27, 2025
56efd9d
Merge branch 'main' into metricsaslogsconnector
kyo-ke Aug 29, 2025
53ce598
Merge branch 'main' into metricsaslogsconnector
kyo-ke Sep 2, 2025
c583dc5
make gencodecov
kyo-ke Sep 2, 2025
e51e5dc
update module version
kyo-ke Sep 2, 2025
ac90551
Merge branch 'main' into metricsaslogsconnector
kyo-ke Sep 3, 2025
2459573
Merge branch 'main' into metricsaslogsconnector
kyo-ke Oct 4, 2025
afe0189
Merge branch 'main' into metricsaslogsconnector
kyo-ke Oct 19, 2025
2a4e632
update mod versions
kyo-ke Oct 19, 2025
8bb8c64
update versions.yaml
kyo-ke Oct 19, 2025
9837c50
Update .chloggen/metricsaslogsconnector.yaml
atoulme Oct 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/metricsaslogsconnector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: new_component

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: metricsaslogsconnector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add connector to convert metrics to logs

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [40938]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ connector/datadogconnector/ @open-telemetry
connector/exceptionsconnector/ @open-telemetry/collector-contrib-approvers @marctc
connector/failoverconnector/ @open-telemetry/collector-contrib-approvers @akats7 @fatsheep9146
connector/grafanacloudconnector/ @open-telemetry/collector-contrib-approvers @rlankfo @jcreixell
connector/metricsaslogsconnector/ @open-telemetry/collector-contrib-approvers @atoulme
connector/otlpjsonconnector/ @open-telemetry/collector-contrib-approvers @ChrsMark
connector/roundrobinconnector/ @open-telemetry/collector-contrib-approvers @bogdandrutu
connector/routingconnector/ @open-telemetry/collector-contrib-approvers @mwear @TylerHelmuth @evan-bradley @edmocosta
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/beta_stability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ body:
- connector/exceptions
- connector/failover
- connector/grafanacloud
- connector/metricsaslogs
- connector/otlpjson
- connector/roundrobin
- connector/routing
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ body:
- connector/exceptions
- connector/failover
- connector/grafanacloud
- connector/metricsaslogs
- connector/otlpjson
- connector/roundrobin
- connector/routing
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ body:
- connector/exceptions
- connector/failover
- connector/grafanacloud
- connector/metricsaslogs
- connector/otlpjson
- connector/roundrobin
- connector/routing
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ body:
- connector/exceptions
- connector/failover
- connector/grafanacloud
- connector/metricsaslogs
- connector/otlpjson
- connector/roundrobin
- connector/routing
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ body:
- connector/exceptions
- connector/failover
- connector/grafanacloud
- connector/metricsaslogs
- connector/otlpjson
- connector/roundrobin
- connector/routing
Expand Down
1 change: 1 addition & 0 deletions .github/component_labels.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ connector/datadogconnector connector/datadog
connector/exceptionsconnector connector/exceptions
connector/failoverconnector connector/failover
connector/grafanacloudconnector connector/grafanacloud
connector/metricsaslogsconnector connector/metricsaslogs
connector/otlpjsonconnector connector/otlpjson
connector/roundrobinconnector connector/roundrobin
connector/routingconnector connector/routing
Expand Down
1 change: 1 addition & 0 deletions connector/metricsaslogsconnector/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
150 changes: 150 additions & 0 deletions connector/metricsaslogsconnector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# metricsaslogsconnector

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Distributions | [] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aconnector%2Fmetricsaslogs%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aconnector%2Fmetricsaslogs) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aconnector%2Fmetricsaslogs%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aconnector%2Fmetricsaslogs) |
| Code coverage | [![codecov](https://codecov.io/github/open-telemetry/opentelemetry-collector-contrib/graph/main/badge.svg?component=connector_metricsaslogs)](https://app.codecov.io/gh/open-telemetry/opentelemetry-collector-contrib/tree/main/?components%5B0%5D=connector_metricsaslogs&displayType=list) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@atoulme](https://www.github.com/atoulme) |

[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development

## Supported Pipeline Types

| [Exporter Pipeline Type] | [Receiver Pipeline Type] | [Stability Level] |
| ------------------------ | ------------------------ | ----------------- |
| metrics | logs | [development] |

[Exporter Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#exporter-pipeline-type
[Receiver Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#receiver-pipeline-type
[Stability Level]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#stability-levels
<!-- end autogenerated section -->

This connector converts OpenTelemetry metrics into logs, creating one log entry per metric data point. Each metric data point is transformed into a structured log record with configurable JSON body format.

## Current Limitations

⚠️ **Current implementation discards the following metric features:**
- Metric exemplars
- Advanced metadata

These features may be added in future iterations.

## Configuration

The following settings can be optionally configured:

- `include_resource_attributes` (default = `true`): Whether to include resource attributes in the generated logs
- `include_scope_info` (default = `true`): Whether to include instrumentation scope information in the generated logs

## Log Body Format

The connector always generates log bodies in the following JSON format:
```json
{"metric_name": "$NAME", "value": "$VALUE"}
```

Where:
- `$NAME` is the actual metric name
- `$VALUE` is the metric value (simple values for gauge/sum, complex JSON for histogram/summary)

## Example Usage

### Basic Configuration

```yaml
connectors:
metricsaslogs:

service:
pipelines:
logs:
receivers: [metricsaslogs]
processors: []
exporters: [logging]
metrics:
receivers: [otlp]
processors: []
exporters: [metricsaslogs]
```

### Advanced Configuration

```yaml
connectors:
metricsaslogs:
include_resource_attributes: false
include_scope_info: false
```


### Example Metric Conversions

For a gauge metric `cpu_usage` with value `85.2`:
```json
{
"body": {"metric_name": "cpu_usage", "value": "85.2"},
"attributes": {
"metric.name": "cpu_usage",
"metric.type": "Gauge",
"metric.description": "CPU usage percentage",
"metric.unit": "%"
}
}
```

For a histogram metric `request_duration`:
```json
{
"body": {
"metric_name": "request_duration",
"value": "{\"count\":100,\"sum\":1.5,\"bucket_counts\":[10,50,40],\"explicit_bounds\":[0.1,0.5,1.0]}"
},
"attributes": {
"metric.name": "request_duration",
"metric.type": "Histogram",
"metric.description": "Request duration in seconds",
"metric.unit": "s",
"metric.aggregation_temporality": "Delta"
}
}
```

## Output Structure

Each metric data point is converted to a log record with:

- **Body**: Fixed JSON format: `{"metric_name": "$NAME", "value": "$VALUE"}`
- **Timestamp**: Metric data point timestamp
- **Observed Timestamp**: Metric data point start timestamp (if available)
- **Attributes**:
- Original metric data point attributes (labels)
- `metric.name`: The metric name
- `metric.type`: The metric type (Gauge, Sum, Histogram, etc.)
- `metric.description`: Metric description (if available)
- `metric.unit`: Metric unit (if available)
- Additional type-specific attributes:
- For Sum metrics: `metric.is_monotonic`, `metric.aggregation_temporality`
- For Histogram/ExponentialHistogram: `metric.aggregation_temporality`
- Resource attributes (if `include_resource_attributes` is true)
- Instrumentation scope information (if `include_scope_info` is true)

## Supported Metric Types

All OpenTelemetry metric types are supported:

- **Gauge**: Point-in-time measurements
- **Sum**: Cumulative or delta measurements
- **Histogram**: Distribution of measurements with buckets
- **Exponential Histogram**: Distribution with exponentially sized buckets
- **Summary**: Distribution with quantile values

## Value Encoding

The `value` field in the JSON body contains:

- For simple metrics (Gauge, Sum): numeric value as string
- For complex metrics (Histogram, etc.): JSON-encoded object as string

All JSON special characters in metric names and values are properly escaped.
27 changes: 27 additions & 0 deletions connector/metricsaslogsconnector/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package metricsaslogsconnector // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/metricsaslogsconnector"

import (
"go.opentelemetry.io/collector/component"
)

type Config struct {
IncludeResourceAttributes bool `mapstructure:"include_resource_attributes"`

IncludeScopeInfo bool `mapstructure:"include_scope_info"`

_ struct{}
}

func (*Config) Validate() error {
return nil
}

func createDefaultConfig() component.Config {
return &Config{
IncludeResourceAttributes: true,
IncludeScopeInfo: true,
}
}
Loading