Skip to content

Commit

Permalink
Add factory implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AkhigbeEromo committed Oct 28, 2024
1 parent 2dfec29 commit e8c5255
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
7 changes: 7 additions & 0 deletions exporter/sematextexporter/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

// Package sematextexporter sends metrics to sematext cloud.
package sematextexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sematextexporter"
69 changes: 69 additions & 0 deletions exporter/sematextexporter/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

//go:generate mdatagen metadata.yaml

package sematextexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sematextexporter"

import (
"context"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/pmetric"

"github.com/influxdata/influxdb-observability/common"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sematextexporter/internal/metadata"
)

const appToken string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

// NewFactory creates a factory for the Sematext exporter.
func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
)
}

func createDefaultConfig() component.Config {
return &Config{
ClientConfig: confighttp.ClientConfig{
Timeout: 5 * time.Second,
Headers: map[string]configopaque.String{
"User-Agent": "OpenTelemetry -> Sematext",
},
},
QueueSettings: exporterhelper.NewDefaultQueueConfig(),
BackOffConfig: configretry.NewDefaultBackOffConfig(),
MetricsSchema: common.MetricsSchemaTelegrafPrometheusV2.String(),
AppToken: appToken,
Region: "custom",
PayloadMaxLines: 1_000,
PayloadMaxBytes: 300_000,
}
}

func createMetricsExporter(
ctx context.Context,
set exporter.Settings,
config component.Config,
) (exporter.Metrics, error) {
cfg := config.(*Config)

return exporterhelper.NewMetrics(
ctx,
set,
cfg,
func(_ context.Context, _ pmetric.Metrics) error {
return nil
},
)
}
17 changes: 17 additions & 0 deletions exporter/sematextexporter/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sematext/default-config:
sematext/override-config:
timeout: 500ms
sending_queue:
enabled: true
num_consumers: 3
queue_size: 10
retry_on_failure:
enabled: true
initial_interval: 1s
max_interval: 3s
max_elapsed_time: 10s
region: US
app_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
metrics_schema: telegraf-prometheus-v2
payload_max_lines: 72
payload_max_bytes: 27

0 comments on commit e8c5255

Please sign in to comment.