|
| 1 | +package io.opentelemetry.instrumentation.api.instrumenter.db; |
| 2 | + |
| 3 | +import io.opentelemetry.api.common.AttributeKey; |
| 4 | +import io.opentelemetry.api.metrics.DoubleHistogramBuilder; |
| 5 | +import io.opentelemetry.api.metrics.LongCounterBuilder; |
| 6 | +import io.opentelemetry.api.metrics.LongUpDownCounterBuilder; |
| 7 | +import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder; |
| 8 | +import io.opentelemetry.extension.incubator.metrics.ExtendedLongCounterBuilder; |
| 9 | +import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder; |
| 10 | +import io.opentelemetry.instrumentation.api.internal.SemconvStability; |
| 11 | +import io.opentelemetry.semconv.SemanticAttributes; |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +final class AerospikeMetricsAdvice { |
| 16 | + private AerospikeMetricsAdvice() {} |
| 17 | + |
| 18 | + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 |
| 19 | + static void applyRequestCounterAdvice(LongCounterBuilder builder) { |
| 20 | + if (!(builder instanceof ExtendedLongCounterBuilder)) { |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + List<AttributeKey<?>> attributes = new ArrayList<>(); |
| 25 | + attributes.add(SemanticAttributes.DB_SYSTEM); |
| 26 | + attributes.add(SemanticAttributes.DB_OPERATION); |
| 27 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); |
| 28 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); |
| 29 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); |
| 30 | + if (SemconvStability.emitStableHttpSemconv()) { |
| 31 | + attributes.add(SemanticAttributes.NETWORK_TYPE); |
| 32 | + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); |
| 33 | + attributes.add(SemanticAttributes.SERVER_ADDRESS); |
| 34 | + attributes.add(SemanticAttributes.SERVER_PORT); |
| 35 | + } |
| 36 | + if (SemconvStability.emitOldHttpSemconv()) { |
| 37 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); |
| 38 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); |
| 39 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); |
| 40 | + } |
| 41 | + |
| 42 | + ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); |
| 43 | + } |
| 44 | + |
| 45 | + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 |
| 46 | + static void applyConcurrencyUpDownCounterAdvice(LongUpDownCounterBuilder builder) { |
| 47 | + if (!(builder instanceof ExtendedLongUpDownCounterBuilder)) { |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + List<AttributeKey<?>> attributes = new ArrayList<>(); |
| 52 | + attributes.add(SemanticAttributes.DB_SYSTEM); |
| 53 | + attributes.add(SemanticAttributes.DB_OPERATION); |
| 54 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); |
| 55 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); |
| 56 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); |
| 57 | + if (SemconvStability.emitStableHttpSemconv()) { |
| 58 | + attributes.add(SemanticAttributes.NETWORK_TYPE); |
| 59 | + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); |
| 60 | + attributes.add(SemanticAttributes.SERVER_ADDRESS); |
| 61 | + attributes.add(SemanticAttributes.SERVER_PORT); |
| 62 | + } |
| 63 | + if (SemconvStability.emitOldHttpSemconv()) { |
| 64 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); |
| 65 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); |
| 66 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); |
| 67 | + } |
| 68 | + |
| 69 | + ((ExtendedLongUpDownCounterBuilder) builder).setAttributesAdvice(attributes); |
| 70 | + } |
| 71 | + |
| 72 | + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 |
| 73 | + static void applyResponseCounterAdvice(LongCounterBuilder builder) { |
| 74 | + if (!(builder instanceof ExtendedLongCounterBuilder)) { |
| 75 | + return; |
| 76 | + } |
| 77 | + |
| 78 | + List<AttributeKey<?>> attributes = new ArrayList<>(); |
| 79 | + attributes.add(SemanticAttributes.DB_SYSTEM); |
| 80 | + attributes.add(SemanticAttributes.DB_OPERATION); |
| 81 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); |
| 82 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); |
| 83 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); |
| 84 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); |
| 85 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); |
| 86 | + if (SemconvStability.emitStableHttpSemconv()) { |
| 87 | + attributes.add(SemanticAttributes.NETWORK_TYPE); |
| 88 | + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); |
| 89 | + attributes.add(SemanticAttributes.SERVER_ADDRESS); |
| 90 | + attributes.add(SemanticAttributes.SERVER_PORT); |
| 91 | + } |
| 92 | + if (SemconvStability.emitOldHttpSemconv()) { |
| 93 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); |
| 94 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); |
| 95 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); |
| 96 | + } |
| 97 | + |
| 98 | + ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); |
| 99 | + } |
| 100 | + |
| 101 | + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 |
| 102 | + static void applyClientDurationAdvice(DoubleHistogramBuilder builder) { |
| 103 | + if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { |
| 104 | + return; |
| 105 | + } |
| 106 | + |
| 107 | + List<AttributeKey<?>> attributes = new ArrayList<>(); |
| 108 | + attributes.add(SemanticAttributes.DB_SYSTEM); |
| 109 | + attributes.add(SemanticAttributes.DB_OPERATION); |
| 110 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); |
| 111 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); |
| 112 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); |
| 113 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); |
| 114 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); |
| 115 | + if (SemconvStability.emitStableHttpSemconv()) { |
| 116 | + attributes.add(SemanticAttributes.NETWORK_TYPE); |
| 117 | + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); |
| 118 | + attributes.add(SemanticAttributes.SERVER_ADDRESS); |
| 119 | + attributes.add(SemanticAttributes.SERVER_PORT); |
| 120 | + } |
| 121 | + if (SemconvStability.emitOldHttpSemconv()) { |
| 122 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); |
| 123 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); |
| 124 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); |
| 125 | + } |
| 126 | + |
| 127 | + ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); |
| 128 | + } |
| 129 | + |
| 130 | + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 |
| 131 | + static void applyRecordSizeAdvice(DoubleHistogramBuilder builder) { |
| 132 | + if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { |
| 133 | + return; |
| 134 | + } |
| 135 | + |
| 136 | + List<AttributeKey<?>> attributes = new ArrayList<>(); |
| 137 | + attributes.add(SemanticAttributes.DB_SYSTEM); |
| 138 | + attributes.add(SemanticAttributes.DB_OPERATION); |
| 139 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); |
| 140 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); |
| 141 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); |
| 142 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); |
| 143 | + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); |
| 144 | + if (SemconvStability.emitStableHttpSemconv()) { |
| 145 | + attributes.add(SemanticAttributes.NETWORK_TYPE); |
| 146 | + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); |
| 147 | + attributes.add(SemanticAttributes.SERVER_ADDRESS); |
| 148 | + attributes.add(SemanticAttributes.SERVER_PORT); |
| 149 | + } |
| 150 | + if (SemconvStability.emitOldHttpSemconv()) { |
| 151 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); |
| 152 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); |
| 153 | + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); |
| 154 | + } |
| 155 | + |
| 156 | + ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); |
| 157 | + } |
| 158 | +} |
0 commit comments