factory.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package cassandraexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/cassandraexporter"
  4. import (
  5. "context"
  6. "fmt"
  7. "time"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/exporter"
  10. "go.opentelemetry.io/collector/exporter/exporterhelper"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/cassandraexporter/internal/metadata"
  12. )
  13. func NewFactory() exporter.Factory {
  14. return exporter.NewFactory(metadata.Type,
  15. createDefaultConfig,
  16. exporter.WithTraces(createTracesExporter, metadata.TracesStability),
  17. exporter.WithLogs(createLogsExporter, metadata.LogsStability),
  18. )
  19. }
  20. func createDefaultConfig() component.Config {
  21. return &Config{
  22. DSN: "127.0.0.1",
  23. Port: 9042,
  24. Timeout: 10 * time.Second,
  25. Keyspace: "otel",
  26. TraceTable: "otel_spans",
  27. LogsTable: "otel_logs",
  28. Replication: Replication{
  29. Class: "SimpleStrategy",
  30. ReplicationFactor: 1,
  31. },
  32. Compression: Compression{
  33. Algorithm: "LZ4Compressor",
  34. },
  35. }
  36. }
  37. func createTracesExporter(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (exporter.Traces, error) {
  38. c := cfg.(*Config)
  39. exp, err := newTracesExporter(set.Logger, c)
  40. if err != nil {
  41. return nil, fmt.Errorf("cannot configure cassandra traces exporter: %w", err)
  42. }
  43. return exporterhelper.NewTracesExporter(ctx, set, cfg, exp.pushTraceData, exporterhelper.WithShutdown(exp.Shutdown), exporterhelper.WithStart(exp.Start))
  44. }
  45. func createLogsExporter(ctx context.Context, set exporter.CreateSettings, cfg component.Config) (exporter.Logs, error) {
  46. c := cfg.(*Config)
  47. exp, err := newLogsExporter(set.Logger, c)
  48. if err != nil {
  49. return nil, fmt.Errorf("cannot configure cassandra traces exporter: %w", err)
  50. }
  51. return exporterhelper.NewLogsExporter(ctx, set, cfg, exp.pushLogsData, exporterhelper.WithShutdown(exp.Shutdown), exporterhelper.WithStart(exp.Start))
  52. }