|
4 | 4 | package groupbyattrsprocessor // import "github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor"
|
5 | 5 |
|
6 | 6 | import (
|
7 |
| - "go.opencensus.io/stats" |
8 |
| - "go.opencensus.io/stats/view" |
| 7 | + "go.opentelemetry.io/collector/component" |
9 | 8 | "go.opentelemetry.io/collector/processor/processorhelper"
|
| 9 | + "go.opentelemetry.io/otel/metric" |
10 | 10 |
|
11 | 11 | "github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor/internal/metadata"
|
12 | 12 | )
|
13 | 13 |
|
14 |
| -var ( |
15 |
| - mNumGroupedSpans = stats.Int64("num_grouped_spans", "Number of spans that had attributes grouped", stats.UnitDimensionless) |
16 |
| - mNumNonGroupedSpans = stats.Int64("num_non_grouped_spans", "Number of spans that did not have attributes grouped", stats.UnitDimensionless) |
17 |
| - mDistSpanGroups = stats.Int64("span_groups", "Distribution of groups extracted for spans", stats.UnitDimensionless) |
| 14 | +type internalTelemetry struct { |
| 15 | + mNumGroupedSpans metric.Int64Counter |
| 16 | + mNumNonGroupedSpans metric.Int64Counter |
| 17 | + mDistSpanGroups metric.Int64Histogram |
18 | 18 |
|
19 |
| - mNumGroupedLogs = stats.Int64("num_grouped_logs", "Number of logs that had attributes grouped", stats.UnitDimensionless) |
20 |
| - mNumNonGroupedLogs = stats.Int64("num_non_grouped_logs", "Number of logs that did not have attributes grouped", stats.UnitDimensionless) |
21 |
| - mDistLogGroups = stats.Int64("log_groups", "Distribution of groups extracted for logs", stats.UnitDimensionless) |
| 19 | + mNumGroupedLogs metric.Int64Counter |
| 20 | + mNumNonGroupedLogs metric.Int64Counter |
| 21 | + mDistLogGroups metric.Int64Histogram |
22 | 22 |
|
23 |
| - mNumGroupedMetrics = stats.Int64("num_grouped_metrics", "Number of metrics that had attributes grouped", stats.UnitDimensionless) |
24 |
| - mNumNonGroupedMetrics = stats.Int64("num_non_grouped_metrics", "Number of metrics that did not have attributes grouped", stats.UnitDimensionless) |
25 |
| - mDistMetricGroups = stats.Int64("metric_groups", "Distribution of groups extracted for metrics", stats.UnitDimensionless) |
26 |
| -) |
| 23 | + mNumGroupedMetrics metric.Int64Counter |
| 24 | + mNumNonGroupedMetrics metric.Int64Counter |
| 25 | + mDistMetricGroups metric.Int64Histogram |
| 26 | +} |
| 27 | + |
| 28 | +func newProcessorTelemetry(set component.TelemetrySettings) (*internalTelemetry, error) { |
| 29 | + it := internalTelemetry{} |
| 30 | + |
| 31 | + counter, err := metadata.Meter(set).Int64Counter( |
| 32 | + processorhelper.BuildCustomMetricName(metadata.Type, "num_grouped_spans"), |
| 33 | + metric.WithDescription("Number of spans that had attributes grouped"), |
| 34 | + metric.WithUnit("1"), |
| 35 | + ) |
| 36 | + if err != nil { |
| 37 | + return nil, err |
| 38 | + } |
| 39 | + it.mNumGroupedSpans = counter |
| 40 | + |
| 41 | + counter, err = metadata.Meter(set).Int64Counter( |
| 42 | + processorhelper.BuildCustomMetricName(metadata.Type, "num_non_grouped_spans"), |
| 43 | + metric.WithDescription("Number of spans that did not have attributes grouped"), |
| 44 | + metric.WithUnit("1"), |
| 45 | + ) |
| 46 | + if err != nil { |
| 47 | + return nil, err |
| 48 | + } |
| 49 | + |
| 50 | + it.mNumNonGroupedSpans = counter |
| 51 | + |
| 52 | + histo, err := metadata.Meter(set).Int64Histogram( |
| 53 | + processorhelper.BuildCustomMetricName(metadata.Type, "span_groups"), |
| 54 | + metric.WithDescription("Distribution of groups extracted for spans"), |
| 55 | + metric.WithUnit("1"), |
| 56 | + ) |
| 57 | + if err != nil { |
| 58 | + return nil, err |
| 59 | + } |
| 60 | + |
| 61 | + it.mDistSpanGroups = histo |
| 62 | + |
| 63 | + counter, err = metadata.Meter(set).Int64Counter( |
| 64 | + processorhelper.BuildCustomMetricName(metadata.Type, "num_grouped_logs"), |
| 65 | + metric.WithDescription("Number of logs that had attributes grouped"), |
| 66 | + metric.WithUnit("1"), |
| 67 | + ) |
| 68 | + if err != nil { |
| 69 | + return nil, err |
| 70 | + } |
| 71 | + it.mNumGroupedLogs = counter |
| 72 | + |
| 73 | + counter, err = metadata.Meter(set).Int64Counter( |
| 74 | + processorhelper.BuildCustomMetricName(metadata.Type, "num_non_grouped_logs"), |
| 75 | + metric.WithDescription("Number of logs that did not have attributes grouped"), |
| 76 | + metric.WithUnit("1"), |
| 77 | + ) |
| 78 | + if err != nil { |
| 79 | + return nil, err |
| 80 | + } |
| 81 | + |
| 82 | + it.mNumNonGroupedLogs = counter |
| 83 | + |
| 84 | + histo, err = metadata.Meter(set).Int64Histogram( |
| 85 | + processorhelper.BuildCustomMetricName(metadata.Type, "log_groups"), |
| 86 | + metric.WithDescription("Distribution of groups extracted for logs"), |
| 87 | + metric.WithUnit("1"), |
| 88 | + ) |
| 89 | + if err != nil { |
| 90 | + return nil, err |
| 91 | + } |
27 | 92 |
|
28 |
| -// metricViews return the metrics views according to given telemetry level. |
29 |
| -func metricViews() []*view.View { |
30 |
| - distributionGroups := view.Distribution(1, 2, 5, 10, 20, 50, 100, 500, 2000) |
31 |
| - |
32 |
| - return []*view.View{ |
33 |
| - { |
34 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mNumGroupedSpans.Name()), |
35 |
| - Measure: mNumGroupedSpans, |
36 |
| - Description: mNumGroupedSpans.Description(), |
37 |
| - Aggregation: view.Sum(), |
38 |
| - }, |
39 |
| - { |
40 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mNumNonGroupedSpans.Name()), |
41 |
| - Measure: mNumNonGroupedSpans, |
42 |
| - Description: mNumNonGroupedSpans.Description(), |
43 |
| - Aggregation: view.Sum(), |
44 |
| - }, |
45 |
| - { |
46 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mDistSpanGroups.Name()), |
47 |
| - Measure: mDistSpanGroups, |
48 |
| - Description: mDistSpanGroups.Description(), |
49 |
| - Aggregation: distributionGroups, |
50 |
| - }, |
51 |
| - |
52 |
| - { |
53 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mNumGroupedLogs.Name()), |
54 |
| - Measure: mNumGroupedLogs, |
55 |
| - Description: mNumGroupedLogs.Description(), |
56 |
| - Aggregation: view.Sum(), |
57 |
| - }, |
58 |
| - { |
59 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mNumNonGroupedLogs.Name()), |
60 |
| - Measure: mNumNonGroupedLogs, |
61 |
| - Description: mNumNonGroupedLogs.Description(), |
62 |
| - Aggregation: view.Sum(), |
63 |
| - }, |
64 |
| - { |
65 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mDistLogGroups.Name()), |
66 |
| - Measure: mDistLogGroups, |
67 |
| - Description: mDistLogGroups.Description(), |
68 |
| - Aggregation: distributionGroups, |
69 |
| - }, |
70 |
| - |
71 |
| - { |
72 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mNumGroupedMetrics.Name()), |
73 |
| - Measure: mNumGroupedMetrics, |
74 |
| - Description: mNumGroupedMetrics.Description(), |
75 |
| - Aggregation: view.Sum(), |
76 |
| - }, |
77 |
| - { |
78 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mNumNonGroupedMetrics.Name()), |
79 |
| - Measure: mNumNonGroupedMetrics, |
80 |
| - Description: mNumNonGroupedMetrics.Description(), |
81 |
| - Aggregation: view.Sum(), |
82 |
| - }, |
83 |
| - { |
84 |
| - Name: processorhelper.BuildCustomMetricName(string(metadata.Type), mDistMetricGroups.Name()), |
85 |
| - Measure: mDistMetricGroups, |
86 |
| - Description: mDistMetricGroups.Description(), |
87 |
| - Aggregation: distributionGroups, |
88 |
| - }, |
| 93 | + it.mDistLogGroups = histo |
| 94 | + |
| 95 | + counter, err = metadata.Meter(set).Int64Counter( |
| 96 | + processorhelper.BuildCustomMetricName(metadata.Type, "num_grouped_metrics"), |
| 97 | + metric.WithDescription("Number of metrics that had attributes grouped"), |
| 98 | + metric.WithUnit("1"), |
| 99 | + ) |
| 100 | + if err != nil { |
| 101 | + return nil, err |
| 102 | + } |
| 103 | + it.mNumGroupedMetrics = counter |
| 104 | + |
| 105 | + counter, err = metadata.Meter(set).Int64Counter( |
| 106 | + processorhelper.BuildCustomMetricName(metadata.Type, "num_non_grouped_metrics"), |
| 107 | + metric.WithDescription("Number of metrics that did not have attributes grouped"), |
| 108 | + metric.WithUnit("1"), |
| 109 | + ) |
| 110 | + if err != nil { |
| 111 | + return nil, err |
89 | 112 | }
|
| 113 | + it.mNumNonGroupedMetrics = counter |
| 114 | + |
| 115 | + histo, err = metadata.Meter(set).Int64Histogram( |
| 116 | + processorhelper.BuildCustomMetricName(metadata.Type, "metric_groups"), |
| 117 | + metric.WithDescription("Distribution of groups extracted for metrics"), |
| 118 | + metric.WithUnit("1"), |
| 119 | + ) |
| 120 | + if err != nil { |
| 121 | + return nil, err |
| 122 | + } |
| 123 | + it.mDistMetricGroups = histo |
| 124 | + |
| 125 | + return &it, nil |
90 | 126 | }
|
0 commit comments