Skip to content

Commit

Permalink
feat(influxdbexporter): add configurable span dimensions (#23230)
Browse files Browse the repository at this point in the history
Adds configurable span dimensions to influxdbexporter. This allows the user to manage which span attributes translate to InfluxDB tags.

Incidentally, this change also updates dependencies of influxdbreceiver, but no material changes are made to that module.
  • Loading branch information
jacobmarble authored Jun 8, 2023
1 parent 9a93eed commit d0fe5f3
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 225 deletions.
20 changes: 20 additions & 0 deletions .chloggen/jgm-span-dimensions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.
# If your change doesn't affect end users, such as a test fix or a tooling change,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add configurable span dimensions

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

# (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:
6 changes: 3 additions & 3 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,9 @@ require (
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6 // indirect
github.com/influxdata/influxdb-observability/common v0.4.3 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.4.3 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.4.3 // indirect
github.com/influxdata/influxdb-observability/common v0.5.0 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.0 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.0 // indirect
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
github.com/ionos-cloud/sdk-go/v6 v6.1.4 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ require (
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/go-syslog/v3 v3.0.1-0.20210608084020-ac565dc76ba6 // indirect
github.com/influxdata/influxdb-observability/common v0.4.3 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.4.3 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.4.3 // indirect
github.com/influxdata/influxdb-observability/common v0.5.0 // indirect
github.com/influxdata/influxdb-observability/influx2otel v0.5.0 // indirect
github.com/influxdata/influxdb-observability/otel2influx v0.5.0 // indirect
github.com/influxdata/line-protocol/v2 v2.2.1 // indirect
github.com/ionos-cloud/sdk-go/v6 v6.1.4 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions exporter/influxdbexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following configuration options are supported:
* `db` (required if enabled) Name of the InfluxDB database to which signals will be written
* `username` (optional) Basic auth username for authenticating with InfluxDB v1.x
* `password` (optional) Basic auth password for authenticating with InfluxDB v1.x
* `span_dimensions` (default = service.name, span.name) Span attributes to use as dimensions (InfluxDB tags)
* `metrics_schema` (default = telegraf-prometheus-v1) The chosen metrics schema to write; must be one of:
* `telegraf-prometheus-v1`
* `telegraf-prometheus-v2`
Expand All @@ -55,6 +56,9 @@ exporters:
org: my-org
bucket: my-bucket
token: my-token
span_dimensions:
- service.name
- span.name
metrics_schema: telegraf-prometheus-v1

sending_queue:
Expand Down
29 changes: 29 additions & 0 deletions exporter/influxdbexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
package influxdbexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/influxdbexporter"

import (
"fmt"
"strings"

"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"golang.org/x/exp/maps"
)

// V1Compatibility is used to specify if the exporter should use the v1.X InfluxDB API schema.
Expand Down Expand Up @@ -36,6 +40,17 @@ type Config struct {
// V1Compatibility is used to specify if the exporter should use the v1.X InfluxDB API schema.
V1Compatibility V1Compatibility `mapstructure:"v1_compatibility"`

// SpanDimensions are span attributes to be used as line protocol tags.
// These are always included as tags:
// - trace ID
// - span ID
// The default values are strongly recommended for use with Jaeger:
// - service.name
// - span.name
// Other common attributes can be found here:
// - https://github.com/open-telemetry/opentelemetry-collector/tree/main/semconv
SpanDimensions []string `mapstructure:"span_dimensions"`

// MetricsSchema indicates the metrics schema to emit to line protocol.
// Options:
// - telegraf-prometheus-v1
Expand All @@ -44,5 +59,19 @@ type Config struct {
}

func (cfg *Config) Validate() error {
uniqueDimensions := make(map[string]struct{}, len(cfg.SpanDimensions))
duplicateDimensions := make(map[string]struct{})
for _, k := range cfg.SpanDimensions {
if _, found := uniqueDimensions[k]; found {
duplicateDimensions[k] = struct{}{}
} else {
uniqueDimensions[k] = struct{}{}
}
}

if len(duplicateDimensions) > 0 {
return fmt.Errorf("duplicate span dimension(s) configured: %s",
strings.Join(maps.Keys(duplicateDimensions), ","))
}
return nil
}
13 changes: 7 additions & 6 deletions exporter/influxdbexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func TestLoadConfig(t *testing.T) {
expected component.Config
}{
{
id: component.NewIDWithName(metadata.Type, ""),
id: component.NewIDWithName(metadata.Type, "default-config"),
expected: createDefaultConfig(),
},
{
id: component.NewIDWithName(metadata.Type, "withsettings"),
id: component.NewIDWithName(metadata.Type, "override-config"),
expected: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: "http://localhost:8080",
Expand All @@ -55,10 +55,11 @@ func TestLoadConfig(t *testing.T) {
RandomizationFactor: backoff.DefaultRandomizationFactor,
Multiplier: backoff.DefaultMultiplier,
},
Org: "my-org",
Bucket: "my-bucket",
Token: "my-token",
MetricsSchema: "telegraf-prometheus-v2",
Org: "my-org",
Bucket: "my-bucket",
Token: "my-token",
SpanDimensions: []string{"service.name", "span.name"},
MetricsSchema: "telegraf-prometheus-v1",
},
},
}
Expand Down
145 changes: 0 additions & 145 deletions exporter/influxdbexporter/exporter.go

This file was deleted.

Loading

0 comments on commit d0fe5f3

Please sign in to comment.