factory.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package awss3exporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awss3exporter"
  4. import (
  5. "context"
  6. "fmt"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/exporter"
  9. "go.opentelemetry.io/collector/exporter/exporterhelper"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awss3exporter/internal/metadata"
  11. )
  12. // NewFactory creates a factory for S3 exporter.
  13. func NewFactory() exporter.Factory {
  14. return exporter.NewFactory(
  15. metadata.Type,
  16. createDefaultConfig,
  17. exporter.WithTraces(createTracesExporter, metadata.TracesStability),
  18. exporter.WithLogs(createLogsExporter, metadata.LogsStability),
  19. exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
  20. )
  21. }
  22. func createDefaultConfig() component.Config {
  23. return &Config{
  24. S3Uploader: S3UploaderConfig{
  25. Region: "us-east-1",
  26. S3Partition: "minute",
  27. },
  28. MarshalerName: "otlp_json",
  29. }
  30. }
  31. func createLogsExporter(ctx context.Context,
  32. params exporter.CreateSettings,
  33. config component.Config) (exporter.Logs, error) {
  34. s3Exporter, err := newS3Exporter(config.(*Config), params)
  35. if err != nil {
  36. return nil, err
  37. }
  38. return exporterhelper.NewLogsExporter(ctx, params,
  39. config,
  40. s3Exporter.ConsumeLogs)
  41. }
  42. func createMetricsExporter(ctx context.Context,
  43. params exporter.CreateSettings,
  44. config component.Config) (exporter.Metrics, error) {
  45. s3Exporter, err := newS3Exporter(config.(*Config), params)
  46. if err != nil {
  47. return nil, err
  48. }
  49. if config.(*Config).MarshalerName == SumoIC {
  50. return nil, fmt.Errorf("metrics are not supported by sumo_ic output format")
  51. }
  52. return exporterhelper.NewMetricsExporter(ctx, params,
  53. config,
  54. s3Exporter.ConsumeMetrics)
  55. }
  56. func createTracesExporter(ctx context.Context,
  57. params exporter.CreateSettings,
  58. config component.Config) (exporter.Traces, error) {
  59. s3Exporter, err := newS3Exporter(config.(*Config), params)
  60. if err != nil {
  61. return nil, err
  62. }
  63. if config.(*Config).MarshalerName == SumoIC {
  64. return nil, fmt.Errorf("traces are not supported by sumo_ic output format")
  65. }
  66. return exporterhelper.NewTracesExporter(ctx,
  67. params,
  68. config,
  69. s3Exporter.ConsumeTraces)
  70. }