|
1 | 1 | # Basic OTLP exporter Example
|
2 | 2 |
|
3 |
| -This example shows basic span and metric usage, and exports to the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP. |
| 3 | +This example shows how to setup OpenTelemetry OTLP exporter for logs, metrics |
| 4 | +and traces to exports them to the [OpenTelemetry |
| 5 | +Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP. |
4 | 6 |
|
5 | 7 | ## Usage
|
6 | 8 |
|
@@ -35,88 +37,219 @@ and inspect the logs to see traces being transferred.
|
35 | 37 | # From the current directory, run `opentelemetry-collector`
|
36 | 38 | $ docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml
|
37 | 39 |
|
38 |
| -# Report spans/metrics |
| 40 | +# Run the app which exports logs, metrics and traces via OTLP to the collector. |
39 | 41 | $ cargo run
|
40 | 42 | ```
|
41 | 43 |
|
42 |
| -# View result |
| 44 | +## View results |
43 | 45 |
|
44 | 46 | You should be able to see something similar below with different time and ID in the same console that docker runs.
|
45 | 47 |
|
46 |
| -## Span |
| 48 | +### Span |
47 | 49 |
|
48 |
| -``` |
49 |
| -Resource labels: |
50 |
| - -> service.name: STRING(trace-demo) |
51 |
| -InstrumentationLibrarySpans #0 |
52 |
| -InstrumentationLibrary |
| 50 | +```text |
| 51 | +2023-09-08T21:50:35.884Z info ResourceSpans #0 |
| 52 | +Resource SchemaURL: |
| 53 | +Resource attributes: |
| 54 | + -> service.name: Str(basic-otlp-tracing-example) |
| 55 | +ScopeSpans #0 |
| 56 | +ScopeSpans SchemaURL: |
| 57 | +InstrumentationScope ex.com/basic |
53 | 58 | Span #0
|
54 |
| - Trace ID : 737d9c966e8250475f400776228c0044 |
55 |
| - Parent ID : ade62a071825f2db |
56 |
| - ID : 7aa9ea5f24e0444c |
| 59 | + Trace ID : f8e7ea4dcab43689cea14f708309d682 |
| 60 | + Parent ID : 8b560e2e7238eab5 |
| 61 | + ID : 9e36b48dc07b32fe |
57 | 62 | Name : Sub operation...
|
58 |
| - Kind : SPAN_KIND_INTERNAL |
59 |
| - Start time : 2022-02-24 04:59:57.218995 +0000 UTC |
60 |
| - End time : 2022-02-24 04:59:57.219022 +0000 UTC |
61 |
| - Status code : STATUS_CODE_UNSET |
| 63 | + Kind : Internal |
| 64 | + Start time : 2023-09-08 21:50:35.872800345 +0000 UTC |
| 65 | + End time : 2023-09-08 21:50:35.87282574 +0000 UTC |
| 66 | + Status code : Unset |
62 | 67 | Status message :
|
63 | 68 | Attributes:
|
64 |
| - -> lemons: STRING(five) |
| 69 | + -> lemons: Str(five) |
65 | 70 | Events:
|
66 | 71 | SpanEvent #0
|
67 | 72 | -> Name: Sub span event
|
68 |
| - -> Timestamp: 2022-02-24 04:59:57.219012 +0000 UTC |
| 73 | + -> Timestamp: 2023-09-08 21:50:35.872808684 +0000 UTC |
69 | 74 | -> DroppedAttributesCount: 0
|
70 | 75 | ResourceSpans #1
|
71 |
| -Resource labels: |
72 |
| - -> service.name: STRING(trace-demo) |
73 |
| -InstrumentationLibrarySpans #0 |
74 |
| -InstrumentationLibrary |
| 76 | +Resource SchemaURL: |
| 77 | +Resource attributes: |
| 78 | + -> service.name: Str(basic-otlp-tracing-example) |
| 79 | +ScopeSpans #0 |
| 80 | +ScopeSpans SchemaURL: |
| 81 | +InstrumentationScope ex.com/basic |
75 | 82 | Span #0
|
76 |
| - Trace ID : 737d9c966e8250475f400776228c0044 |
| 83 | + Trace ID : f8e7ea4dcab43689cea14f708309d682 |
77 | 84 | Parent ID :
|
78 |
| - ID : ade62a071825f2db |
| 85 | + ID : 8b560e2e7238eab5 |
79 | 86 | Name : operation
|
80 |
| - Kind : SPAN_KIND_INTERNAL |
81 |
| - Start time : 2022-02-24 04:59:57.218877 +0000 UTC |
82 |
| - End time : 2022-02-24 04:59:57.219043 +0000 UTC |
83 |
| - Status code : STATUS_CODE_UNSET |
| 87 | + Kind : Internal |
| 88 | + Start time : 2023-09-08 21:50:35.872735497 +0000 UTC |
| 89 | + End time : 2023-09-08 21:50:35.872832026 +0000 UTC |
| 90 | + Status code : Unset |
84 | 91 | Status message :
|
85 | 92 | Attributes:
|
86 |
| - -> ex.com/another: STRING(yes) |
| 93 | + -> ex.com/another: Str(yes) |
87 | 94 | Events:
|
88 | 95 | SpanEvent #0
|
89 | 96 | -> Name: Nice operation!
|
90 |
| - -> Timestamp: 2022-02-24 04:59:57.218896 +0000 UTC |
| 97 | + -> Timestamp: 2023-09-08 21:50:35.872750123 +0000 UTC |
91 | 98 | -> DroppedAttributesCount: 0
|
92 |
| - -> Attributes: |
93 |
| - -> bogons: INT(100) |
| 99 | + -> Attributes:: |
| 100 | + -> bogons: Int(100) |
| 101 | + {"kind": "exporter", "data_type": "traces", "name": "logging"} |
94 | 102 | ```
|
95 | 103 |
|
96 |
| -## Metric |
| 104 | +### Metric |
97 | 105 |
|
98 |
| -``` |
99 |
| -2021-11-19T04:08:36.453Z INFO loggingexporter/logging_exporter.go:56 MetricsExporter {"#metrics": 1} |
100 |
| -2021-11-19T04:08:36.454Z DEBUG loggingexporter/logging_exporter.go:66 ResourceMetrics #0 |
101 |
| -Resource labels: |
102 |
| - -> service.name: STRING(unknown_service) |
103 |
| -InstrumentationLibraryMetrics #0 |
104 |
| -InstrumentationLibrary ex.com/basic |
| 106 | +```text |
| 107 | +2023-09-08T19:14:12.522Z info ResourceMetrics #0 |
| 108 | +Resource SchemaURL: |
| 109 | +Resource attributes: |
| 110 | + -> service.name: Str(basic-otlp-metrics-example) |
| 111 | +ScopeMetrics #0 |
| 112 | +ScopeMetrics SchemaURL: |
| 113 | +InstrumentationScope ex.com/basic |
105 | 114 | Metric #0
|
106 | 115 | Descriptor:
|
107 | 116 | -> Name: ex.com.one
|
108 |
| - -> Description: A ValueObserver set to 1.0 |
| 117 | + -> Description: A gauge set to 1.0 |
109 | 118 | -> Unit:
|
110 | 119 | -> DataType: Gauge
|
111 | 120 | NumberDataPoints #0
|
112 | 121 | Data point attributes:
|
113 |
| - -> A: STRING(1) |
114 |
| - -> B: STRING(2) |
115 |
| - -> C: STRING(3) |
116 |
| - -> lemons: INT(10) |
117 |
| -StartTimestamp: 2021-11-19 04:07:46.29555 +0000 UTC |
118 |
| -Timestamp: 2021-11-19 04:08:36.297279 +0000 UTC |
| 122 | + -> A: Str(1) |
| 123 | + -> B: Str(2) |
| 124 | + -> C: Str(3) |
| 125 | + -> lemons: Int(10) |
| 126 | +StartTimestamp: 1970-01-01 00:00:00 +0000 UTC |
| 127 | +Timestamp: 2023-09-08 19:14:12.468030127 +0000 UTC |
119 | 128 | Value: 1.000000
|
| 129 | +Metric #1 |
| 130 | +Descriptor: |
| 131 | + -> Name: ex.com.two |
| 132 | + -> Description: |
| 133 | + -> Unit: |
| 134 | + -> DataType: Histogram |
| 135 | + -> AggregationTemporality: Cumulative |
| 136 | +HistogramDataPoints #0 |
| 137 | +Data point attributes: |
| 138 | + -> A: Str(1) |
| 139 | + -> B: Str(2) |
| 140 | + -> C: Str(3) |
| 141 | + -> lemons: Int(10) |
| 142 | +StartTimestamp: 2023-09-08 19:14:12.466896812 +0000 UTC |
| 143 | +Timestamp: 2023-09-08 19:14:12.468052807 +0000 UTC |
| 144 | +Count: 1 |
| 145 | +Sum: 5.500000 |
| 146 | +Min: 5.500000 |
| 147 | +Max: 5.500000 |
| 148 | +ExplicitBounds #0: 0.000000 |
| 149 | +ExplicitBounds #1: 5.000000 |
| 150 | +ExplicitBounds #2: 10.000000 |
| 151 | +ExplicitBounds #3: 25.000000 |
| 152 | +ExplicitBounds #4: 50.000000 |
| 153 | +ExplicitBounds #5: 75.000000 |
| 154 | +ExplicitBounds #6: 100.000000 |
| 155 | +ExplicitBounds #7: 250.000000 |
| 156 | +ExplicitBounds #8: 500.000000 |
| 157 | +ExplicitBounds #9: 750.000000 |
| 158 | +ExplicitBounds #10: 1000.000000 |
| 159 | +ExplicitBounds #11: 2500.000000 |
| 160 | +ExplicitBounds #12: 5000.000000 |
| 161 | +ExplicitBounds #13: 7500.000000 |
| 162 | +ExplicitBounds #14: 10000.000000 |
| 163 | +Buckets #0, Count: 0 |
| 164 | +Buckets #1, Count: 0 |
| 165 | +Buckets #2, Count: 1 |
| 166 | +Buckets #3, Count: 0 |
| 167 | +Buckets #4, Count: 0 |
| 168 | +Buckets #5, Count: 0 |
| 169 | +Buckets #6, Count: 0 |
| 170 | +Buckets #7, Count: 0 |
| 171 | +Buckets #8, Count: 0 |
| 172 | +Buckets #9, Count: 0 |
| 173 | +Buckets #10, Count: 0 |
| 174 | +Buckets #11, Count: 0 |
| 175 | +Buckets #12, Count: 0 |
| 176 | +Buckets #13, Count: 0 |
| 177 | +Buckets #14, Count: 0 |
| 178 | +Buckets #15, Count: 0 |
| 179 | +HistogramDataPoints #1 |
| 180 | +StartTimestamp: 2023-09-08 19:14:12.466896812 +0000 UTC |
| 181 | +Timestamp: 2023-09-08 19:14:12.468052807 +0000 UTC |
| 182 | +Count: 1 |
| 183 | +Sum: 1.300000 |
| 184 | +Min: 1.300000 |
| 185 | +Max: 1.300000 |
| 186 | +ExplicitBounds #0: 0.000000 |
| 187 | +ExplicitBounds #1: 5.000000 |
| 188 | +ExplicitBounds #2: 10.000000 |
| 189 | +ExplicitBounds #3: 25.000000 |
| 190 | +ExplicitBounds #4: 50.000000 |
| 191 | +ExplicitBounds #5: 75.000000 |
| 192 | +ExplicitBounds #6: 100.000000 |
| 193 | +ExplicitBounds #7: 250.000000 |
| 194 | +ExplicitBounds #8: 500.000000 |
| 195 | +ExplicitBounds #9: 750.000000 |
| 196 | +ExplicitBounds #10: 1000.000000 |
| 197 | +ExplicitBounds #11: 2500.000000 |
| 198 | +ExplicitBounds #12: 5000.000000 |
| 199 | +ExplicitBounds #13: 7500.000000 |
| 200 | +ExplicitBounds #14: 10000.000000 |
| 201 | +Buckets #0, Count: 0 |
| 202 | +Buckets #1, Count: 1 |
| 203 | +Buckets #2, Count: 0 |
| 204 | +Buckets #3, Count: 0 |
| 205 | +Buckets #4, Count: 0 |
| 206 | +Buckets #5, Count: 0 |
| 207 | +Buckets #6, Count: 0 |
| 208 | +Buckets #7, Count: 0 |
| 209 | +Buckets #8, Count: 0 |
| 210 | +Buckets #9, Count: 0 |
| 211 | +Buckets #10, Count: 0 |
| 212 | +Buckets #11, Count: 0 |
| 213 | +Buckets #12, Count: 0 |
| 214 | +Buckets #13, Count: 0 |
| 215 | +Buckets #14, Count: 0 |
| 216 | +Buckets #15, Count: 0 |
| 217 | + {"kind": "exporter", "data_type": "metrics", "name": "logging"} |
120 | 218 | ```
|
121 | 219 |
|
122 |
| - |
| 220 | +### Logs |
| 221 | + |
| 222 | +```text |
| 223 | +2023-09-08T21:50:35.884Z info ResourceLog #0 |
| 224 | +Resource SchemaURL: |
| 225 | +Resource attributes: |
| 226 | + -> service.name: Str(basic-otlp-logging-example) |
| 227 | +ScopeLogs #0 |
| 228 | +ScopeLogs SchemaURL: |
| 229 | +InstrumentationScope opentelemetry-log-appender 0.1.0 |
| 230 | +LogRecord #0 |
| 231 | +ObservedTimestamp: 2023-09-08 21:50:35.872759168 +0000 UTC |
| 232 | +Timestamp: 1970-01-01 00:00:00 +0000 UTC |
| 233 | +SeverityText: INFO |
| 234 | +SeverityNumber: Info(9) |
| 235 | +Body: Str(hello from banana. My price is 2.99. I am also inside a Span!) |
| 236 | +Trace ID: f8e7ea4dcab43689cea14f708309d682 |
| 237 | +Span ID: 8b560e2e7238eab5 |
| 238 | +Flags: 1 |
| 239 | +ResourceLog #1 |
| 240 | +Resource SchemaURL: |
| 241 | +Resource attributes: |
| 242 | + -> service.name: Str(basic-otlp-logging-example) |
| 243 | +ScopeLogs #0 |
| 244 | +ScopeLogs SchemaURL: |
| 245 | +InstrumentationScope opentelemetry-log-appender 0.1.0 |
| 246 | +LogRecord #0 |
| 247 | +ObservedTimestamp: 2023-09-08 21:50:35.872833713 +0000 UTC |
| 248 | +Timestamp: 1970-01-01 00:00:00 +0000 UTC |
| 249 | +SeverityText: INFO |
| 250 | +SeverityNumber: Info(9) |
| 251 | +Body: Str(hello from apple. My price is 1.99) |
| 252 | +Trace ID: |
| 253 | +Span ID: |
| 254 | +Flags: 0 |
| 255 | +``` |
0 commit comments