factory.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package awsemfexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter"
  4. import (
  5. "context"
  6. "go.opentelemetry.io/collector/component"
  7. "go.opentelemetry.io/collector/exporter"
  8. "go.opentelemetry.io/collector/exporter/exporterhelper"
  9. "go.opentelemetry.io/collector/featuregate"
  10. "go.uber.org/zap"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter/internal/metadata"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
  14. )
  15. var defaultNoRollupfg = featuregate.GlobalRegistry().MustRegister("awsemf.nodimrollupdefault", featuregate.StageAlpha,
  16. featuregate.WithRegisterFromVersion("v0.83.0"),
  17. featuregate.WithRegisterDescription("Changes the default AWS EMF Exporter Dimension rollup option to "+
  18. "NoDimensionRollup"))
  19. // NewFactory creates a factory for AWS EMF exporter.
  20. func NewFactory() exporter.Factory {
  21. return exporter.NewFactory(
  22. metadata.Type,
  23. createDefaultConfig,
  24. exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability))
  25. }
  26. // CreateDefaultConfig creates the default configuration for exporter.
  27. func createDefaultConfig() component.Config {
  28. var defaultDimensionRollupOption string
  29. if defaultNoRollupfg.IsEnabled() {
  30. defaultDimensionRollupOption = "NoDimensionRollup"
  31. } else {
  32. defaultDimensionRollupOption = "ZeroAndSingleDimensionRollup"
  33. }
  34. return &Config{
  35. AWSSessionSettings: awsutil.CreateDefaultSessionConfig(),
  36. LogGroupName: "",
  37. LogStreamName: "",
  38. Namespace: "",
  39. DimensionRollupOption: defaultDimensionRollupOption,
  40. Version: "1",
  41. RetainInitialValueOfDeltaMetric: false,
  42. OutputDestination: "cloudwatch",
  43. logger: zap.NewNop(),
  44. }
  45. }
  46. // createMetricsExporter creates a metrics exporter based on this config.
  47. func createMetricsExporter(ctx context.Context, params exporter.CreateSettings, config component.Config) (exporter.Metrics, error) {
  48. expCfg := config.(*Config)
  49. emfExp, err := newEmfExporter(expCfg, params)
  50. if err != nil {
  51. return nil, err
  52. }
  53. exporter, err := exporterhelper.NewMetricsExporter(
  54. ctx,
  55. params,
  56. config,
  57. emfExp.pushMetricsData,
  58. exporterhelper.WithShutdown(emfExp.shutdown),
  59. )
  60. if err != nil {
  61. return nil, err
  62. }
  63. return resourcetotelemetry.WrapMetricsExporter(expCfg.ResourceToTelemetrySettings, exporter), nil
  64. }