66package io .opentelemetry .instrumentation .iceberg .v1_8 ;
77
88import io .opentelemetry .api .OpenTelemetry ;
9+ import io .opentelemetry .api .common .AttributeKey ;
10+ import io .opentelemetry .api .common .Attributes ;
911import io .opentelemetry .api .metrics .LongCounter ;
1012import io .opentelemetry .api .metrics .LongGauge ;
1113import org .apache .iceberg .metrics .CommitReport ;
1820
1921public class IcebergMetricsReporter implements MetricsReporter {
2022 private static final String INSTRUMENTATION_NAME = "io.opentelemetry.iceberg_1.8" ;
23+ private static final AttributeKey <Long > SCHEMA_ID = AttributeKey .longKey ("iceberg.schema.id" );
24+ private static final AttributeKey <String > TABLE_NAME =
25+ AttributeKey .stringKey ("iceberg.table.name" );
26+ private static final AttributeKey <Long > SNAPHSOT_ID = AttributeKey .longKey ("iceberg.snapshot.id" );
2127
2228 private final OpenTelemetry openTelemetry ;
2329
@@ -35,29 +41,37 @@ public void report(MetricsReport report) {
3541 }
3642
3743 void reportScanMetrics (ScanReport scanReport ) {
44+ Attributes scanAttributes =
45+ Attributes .of (
46+ SCHEMA_ID ,
47+ Long .valueOf (scanReport .schemaId ()),
48+ TABLE_NAME ,
49+ scanReport .tableName (),
50+ SNAPHSOT_ID ,
51+ scanReport .snapshotId ());
3852 ScanMetricsResult metrics = scanReport .scanMetrics ();
3953 TimerResult duration = metrics .totalPlanningDuration ();
4054
4155 if (duration != null ) {
4256 LongGauge metric =
4357 ScanMetricsBuilder .totalPlanningDuration (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
44- metric .set (duration .totalDuration ().toMillis ());
58+ metric .set (duration .totalDuration ().toMillis (), scanAttributes );
4559 }
4660
4761 CounterResult current = metrics .resultDataFiles ();
4862
4963 if (current != null ) {
5064 LongCounter metric =
5165 ScanMetricsBuilder .scannedDataFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
52- metric .add (current .value ());
66+ metric .add (current .value (), scanAttributes );
5367 }
5468
5569 current = metrics .resultDeleteFiles ();
5670
5771 if (current != null ) {
5872 LongCounter metric =
5973 ScanMetricsBuilder .scannedDeleteFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
60- metric .add (current .value ());
74+ metric .add (current .value (), scanAttributes );
6175 }
6276
6377 current = metrics .scannedDataManifests ();
@@ -66,7 +80,7 @@ void reportScanMetrics(ScanReport scanReport) {
6680 LongCounter metric =
6781 ScanMetricsBuilder .scannedDataManifestsCount (
6882 openTelemetry .getMeter (INSTRUMENTATION_NAME ));
69- metric .add (current .value ());
83+ metric .add (current .value (), scanAttributes );
7084 }
7185
7286 current = metrics .scannedDeleteManifests ();
@@ -75,15 +89,15 @@ void reportScanMetrics(ScanReport scanReport) {
7589 LongCounter metric =
7690 ScanMetricsBuilder .scannedDeleteManifestsCount (
7791 openTelemetry .getMeter (INSTRUMENTATION_NAME ));
78- metric .add (current .value ());
92+ metric .add (current .value (), scanAttributes );
7993 }
8094
8195 current = metrics .totalDataManifests ();
8296
8397 if (current != null ) {
8498 LongCounter metric =
8599 ScanMetricsBuilder .totalDataManifestsCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
86- metric .add (current .value ());
100+ metric .add (current .value (), scanAttributes );
87101 }
88102
89103 current = metrics .totalDeleteManifests ();
@@ -92,23 +106,23 @@ void reportScanMetrics(ScanReport scanReport) {
92106 LongCounter metric =
93107 ScanMetricsBuilder .totalDeleteManifestsCount (
94108 openTelemetry .getMeter (INSTRUMENTATION_NAME ));
95- metric .add (current .value ());
109+ metric .add (current .value (), scanAttributes );
96110 }
97111
98112 current = metrics .totalFileSizeInBytes ();
99113
100114 if (current != null ) {
101115 LongCounter metric =
102116 ScanMetricsBuilder .scannedDataFilesSize (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
103- metric .add (current .value ());
117+ metric .add (current .value (), scanAttributes );
104118 }
105119
106120 current = metrics .totalDeleteFileSizeInBytes ();
107121
108122 if (current != null ) {
109123 LongCounter metric =
110124 ScanMetricsBuilder .scannedDeleteFilesSize (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
111- metric .add (current .value ());
125+ metric .add (current .value (), scanAttributes );
112126 }
113127
114128 current = metrics .skippedDataManifests ();
@@ -117,7 +131,7 @@ void reportScanMetrics(ScanReport scanReport) {
117131 LongCounter metric =
118132 ScanMetricsBuilder .skippedDataManifestsCount (
119133 openTelemetry .getMeter (INSTRUMENTATION_NAME ));
120- metric .add (current .value ());
134+ metric .add (current .value (), scanAttributes );
121135 }
122136
123137 current = metrics .skippedDeleteManifests ();
@@ -126,55 +140,55 @@ void reportScanMetrics(ScanReport scanReport) {
126140 LongCounter metric =
127141 ScanMetricsBuilder .skippedDeleteManifestsCount (
128142 openTelemetry .getMeter (INSTRUMENTATION_NAME ));
129- metric .add (current .value ());
143+ metric .add (current .value (), scanAttributes );
130144 }
131145
132146 current = metrics .skippedDataFiles ();
133147
134148 if (current != null ) {
135149 LongCounter metric =
136150 ScanMetricsBuilder .skippedDataFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
137- metric .add (current .value ());
151+ metric .add (current .value (), scanAttributes );
138152 }
139153
140154 current = metrics .skippedDeleteFiles ();
141155
142156 if (current != null ) {
143157 LongCounter metric =
144158 ScanMetricsBuilder .skippedDeleteFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
145- metric .add (current .value ());
159+ metric .add (current .value (), scanAttributes );
146160 }
147161
148162 current = metrics .indexedDeleteFiles ();
149163
150164 if (current != null ) {
151165 LongCounter metric =
152166 ScanMetricsBuilder .indexedDeleteFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
153- metric .add (current .value ());
167+ metric .add (current .value (), scanAttributes );
154168 }
155169
156170 current = metrics .equalityDeleteFiles ();
157171
158172 if (current != null ) {
159173 LongCounter metric =
160174 ScanMetricsBuilder .equalityDeleteFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
161- metric .add (current .value ());
175+ metric .add (current .value (), scanAttributes );
162176 }
163177
164178 current = metrics .positionalDeleteFiles ();
165179
166180 if (current != null ) {
167181 LongCounter metric =
168182 ScanMetricsBuilder .positionDeleteFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
169- metric .add (current .value ());
183+ metric .add (current .value (), scanAttributes );
170184 }
171185
172186 current = metrics .dvs ();
173187
174188 if (current != null ) {
175189 LongCounter metric =
176190 ScanMetricsBuilder .deletionVectorFilesCount (openTelemetry .getMeter (INSTRUMENTATION_NAME ));
177- metric .add (current .value ());
191+ metric .add (current .value (), scanAttributes );
178192 }
179193 }
180194
0 commit comments