|
1 |
| -* The application send data directly to a Collector (port 4318) |
2 |
| -* Run the application locally, to run as a docker container you have to change the relative paths from the `Cargo.toml` |
3 |
| -* The Collector then sends the data to the appropriate backend, in this case Debug Exporter. The Debug Exporter exports data to console. |
| 1 | +# Basic OTLP exporter Example |
4 | 2 |
|
5 |
| -This demo uses `docker-compose` and by default runs against the `otel/opentelemetry-collector-dev:latest` image, |
6 |
| -and uses `http` as the transport. |
| 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 over HTTP. |
| 6 | +The Collector then sends the data to the appropriate backend, in this case, |
| 7 | +the logging Exporter, which displays data to console. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +### `docker-compose` |
| 12 | + |
| 13 | +By default runs against the `otel/opentelemetry-collector:latest` image, and uses `reqwest-client` |
| 14 | +as the http client, using http as the transport. |
7 | 15 |
|
8 | 16 | ```shell
|
9 | 17 | docker-compose up
|
10 | 18 | ```
|
11 | 19 |
|
12 | 20 | In another terminal run the application `cargo run`
|
13 | 21 |
|
14 |
| -The docker-compose terminal will display logs, metrics and traces. |
| 22 | +The docker-compose terminal will display logs, traces, metrics. |
15 | 23 |
|
16 |
| -Tear it down: |
| 24 | +Press Ctrl+C to stop the collector, and then tear it down: |
17 | 25 |
|
18 | 26 | ```shell
|
19 | 27 | docker-compose down
|
20 | 28 | ```
|
21 | 29 |
|
| 30 | +### Manual |
| 31 | + |
| 32 | +If you don't want to use `docker-compose`, you can manually run the `otel/opentelemetry-collector` container |
| 33 | +and inspect the logs to see traces being transferred. |
| 34 | + |
| 35 | +```shell |
| 36 | +# From the current directory, run `opentelemetry-collector` |
| 37 | +$ docker run --rm -it -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml |
| 38 | + |
| 39 | +# Run the app which exports logs, metrics and traces via OTLP to the collector. |
| 40 | +$ cargo run |
| 41 | +``` |
| 42 | + |
| 43 | +## View results |
22 | 44 |
|
| 45 | +You should be able to see something similar below with different time and ID in the same console that docker runs. |
| 46 | + |
| 47 | +### Span |
| 48 | + |
| 49 | +```text |
| 50 | +2023-09-08T21:50:35.884Z info ResourceSpans #0 |
| 51 | +Resource SchemaURL: |
| 52 | +Resource attributes: |
| 53 | + -> service.name: Str(basic-otlp-tracing-example) |
| 54 | +ScopeSpans #0 |
| 55 | +ScopeSpans SchemaURL: |
| 56 | +InstrumentationScope ex.com/basic |
| 57 | +Span #0 |
| 58 | + Trace ID : f8e7ea4dcab43689cea14f708309d682 |
| 59 | + Parent ID : 8b560e2e7238eab5 |
| 60 | + ID : 9e36b48dc07b32fe |
| 61 | + Name : Sub operation... |
| 62 | + Kind : Internal |
| 63 | + Start time : 2023-09-08 21:50:35.872800345 +0000 UTC |
| 64 | + End time : 2023-09-08 21:50:35.87282574 +0000 UTC |
| 65 | + Status code : Unset |
| 66 | + Status message : |
| 67 | +Attributes: |
| 68 | + -> lemons: Str(five) |
| 69 | +Events: |
| 70 | +SpanEvent #0 |
| 71 | + -> Name: Sub span event |
| 72 | + -> Timestamp: 2023-09-08 21:50:35.872808684 +0000 UTC |
| 73 | + -> DroppedAttributesCount: 0 |
| 74 | +ResourceSpans #1 |
| 75 | +Resource SchemaURL: |
| 76 | +Resource attributes: |
| 77 | + -> service.name: Str(basic-otlp-tracing-example) |
| 78 | +ScopeSpans #0 |
| 79 | +ScopeSpans SchemaURL: |
| 80 | +InstrumentationScope ex.com/basic |
| 81 | +Span #0 |
| 82 | + Trace ID : f8e7ea4dcab43689cea14f708309d682 |
| 83 | + Parent ID : |
| 84 | + ID : 8b560e2e7238eab5 |
| 85 | + Name : operation |
| 86 | + Kind : Internal |
| 87 | + Start time : 2023-09-08 21:50:35.872735497 +0000 UTC |
| 88 | + End time : 2023-09-08 21:50:35.872832026 +0000 UTC |
| 89 | + Status code : Unset |
| 90 | + Status message : |
| 91 | +Attributes: |
| 92 | + -> ex.com/another: Str(yes) |
| 93 | +Events: |
| 94 | +SpanEvent #0 |
| 95 | + -> Name: Nice operation! |
| 96 | + -> Timestamp: 2023-09-08 21:50:35.872750123 +0000 UTC |
| 97 | + -> DroppedAttributesCount: 0 |
| 98 | + -> Attributes:: |
| 99 | + -> bogons: Int(100) |
| 100 | + {"kind": "exporter", "data_type": "traces", "name": "logging"} |
| 101 | +``` |
| 102 | + |
| 103 | +### Metric |
| 104 | + |
| 105 | +```text |
| 106 | +2023-09-08T19:14:12.522Z info ResourceMetrics #0 |
| 107 | +Resource SchemaURL: |
| 108 | +Resource attributes: |
| 109 | + -> service.name: Str(basic-otlp-metrics-example) |
| 110 | +ScopeMetrics #0 |
| 111 | +ScopeMetrics SchemaURL: |
| 112 | +InstrumentationScope ex.com/basic |
| 113 | +Metric #0 |
| 114 | +Descriptor: |
| 115 | + -> Name: ex.com.one |
| 116 | + -> Description: A gauge set to 1.0 |
| 117 | + -> Unit: |
| 118 | + -> DataType: Gauge |
| 119 | +NumberDataPoints #0 |
| 120 | +Data point attributes: |
| 121 | + -> A: Str(1) |
| 122 | + -> B: Str(2) |
| 123 | + -> C: Str(3) |
| 124 | + -> lemons: Int(10) |
| 125 | +StartTimestamp: 1970-01-01 00:00:00 +0000 UTC |
| 126 | +Timestamp: 2023-09-08 19:14:12.468030127 +0000 UTC |
| 127 | +Value: 1.000000 |
| 128 | +Metric #1 |
| 129 | +Descriptor: |
| 130 | + -> Name: ex.com.two |
| 131 | + -> Description: |
| 132 | + -> Unit: |
| 133 | + -> DataType: Histogram |
| 134 | + -> AggregationTemporality: Cumulative |
| 135 | +HistogramDataPoints #0 |
| 136 | +Data point attributes: |
| 137 | + -> A: Str(1) |
| 138 | + -> B: Str(2) |
| 139 | + -> C: Str(3) |
| 140 | + -> lemons: Int(10) |
| 141 | +StartTimestamp: 2023-09-08 19:14:12.466896812 +0000 UTC |
| 142 | +Timestamp: 2023-09-08 19:14:12.468052807 +0000 UTC |
| 143 | +Count: 1 |
| 144 | +Sum: 5.500000 |
| 145 | +Min: 5.500000 |
| 146 | +Max: 5.500000 |
| 147 | +ExplicitBounds #0: 0.000000 |
| 148 | +ExplicitBounds #1: 5.000000 |
| 149 | +ExplicitBounds #2: 10.000000 |
| 150 | +ExplicitBounds #3: 25.000000 |
| 151 | +ExplicitBounds #4: 50.000000 |
| 152 | +ExplicitBounds #5: 75.000000 |
| 153 | +ExplicitBounds #6: 100.000000 |
| 154 | +ExplicitBounds #7: 250.000000 |
| 155 | +ExplicitBounds #8: 500.000000 |
| 156 | +ExplicitBounds #9: 750.000000 |
| 157 | +ExplicitBounds #10: 1000.000000 |
| 158 | +ExplicitBounds #11: 2500.000000 |
| 159 | +ExplicitBounds #12: 5000.000000 |
| 160 | +ExplicitBounds #13: 7500.000000 |
| 161 | +ExplicitBounds #14: 10000.000000 |
| 162 | +Buckets #0, Count: 0 |
| 163 | +Buckets #1, Count: 0 |
| 164 | +Buckets #2, Count: 1 |
| 165 | +Buckets #3, Count: 0 |
| 166 | +Buckets #4, Count: 0 |
| 167 | +Buckets #5, Count: 0 |
| 168 | +Buckets #6, Count: 0 |
| 169 | +Buckets #7, Count: 0 |
| 170 | +Buckets #8, Count: 0 |
| 171 | +Buckets #9, Count: 0 |
| 172 | +Buckets #10, Count: 0 |
| 173 | +Buckets #11, Count: 0 |
| 174 | +Buckets #12, Count: 0 |
| 175 | +Buckets #13, Count: 0 |
| 176 | +Buckets #14, Count: 0 |
| 177 | +Buckets #15, Count: 0 |
| 178 | +HistogramDataPoints #1 |
| 179 | +StartTimestamp: 2023-09-08 19:14:12.466896812 +0000 UTC |
| 180 | +Timestamp: 2023-09-08 19:14:12.468052807 +0000 UTC |
| 181 | +Count: 1 |
| 182 | +Sum: 1.300000 |
| 183 | +Min: 1.300000 |
| 184 | +Max: 1.300000 |
| 185 | +ExplicitBounds #0: 0.000000 |
| 186 | +ExplicitBounds #1: 5.000000 |
| 187 | +ExplicitBounds #2: 10.000000 |
| 188 | +ExplicitBounds #3: 25.000000 |
| 189 | +ExplicitBounds #4: 50.000000 |
| 190 | +ExplicitBounds #5: 75.000000 |
| 191 | +ExplicitBounds #6: 100.000000 |
| 192 | +ExplicitBounds #7: 250.000000 |
| 193 | +ExplicitBounds #8: 500.000000 |
| 194 | +ExplicitBounds #9: 750.000000 |
| 195 | +ExplicitBounds #10: 1000.000000 |
| 196 | +ExplicitBounds #11: 2500.000000 |
| 197 | +ExplicitBounds #12: 5000.000000 |
| 198 | +ExplicitBounds #13: 7500.000000 |
| 199 | +ExplicitBounds #14: 10000.000000 |
| 200 | +Buckets #0, Count: 0 |
| 201 | +Buckets #1, Count: 1 |
| 202 | +Buckets #2, Count: 0 |
| 203 | +Buckets #3, Count: 0 |
| 204 | +Buckets #4, Count: 0 |
| 205 | +Buckets #5, Count: 0 |
| 206 | +Buckets #6, Count: 0 |
| 207 | +Buckets #7, Count: 0 |
| 208 | +Buckets #8, Count: 0 |
| 209 | +Buckets #9, Count: 0 |
| 210 | +Buckets #10, Count: 0 |
| 211 | +Buckets #11, Count: 0 |
| 212 | +Buckets #12, Count: 0 |
| 213 | +Buckets #13, Count: 0 |
| 214 | +Buckets #14, Count: 0 |
| 215 | +Buckets #15, Count: 0 |
| 216 | + {"kind": "exporter", "data_type": "metrics", "name": "logging"} |
| 217 | +``` |
| 218 | + |
| 219 | +### Logs |
| 220 | + |
| 221 | +```text |
| 222 | +2023-09-08T21:50:35.884Z info ResourceLog #0 |
| 223 | +Resource SchemaURL: |
| 224 | +Resource attributes: |
| 225 | + -> service.name: Str(basic-otlp-logging-example) |
| 226 | +ScopeLogs #0 |
| 227 | +ScopeLogs SchemaURL: |
| 228 | +InstrumentationScope opentelemetry-log-appender 0.1.0 |
| 229 | +LogRecord #0 |
| 230 | +ObservedTimestamp: 2023-09-08 21:50:35.872759168 +0000 UTC |
| 231 | +Timestamp: 1970-01-01 00:00:00 +0000 UTC |
| 232 | +SeverityText: INFO |
| 233 | +SeverityNumber: Info(9) |
| 234 | +Body: Str(hello from banana. My price is 2.99. I am also inside a Span!) |
| 235 | +Trace ID: f8e7ea4dcab43689cea14f708309d682 |
| 236 | +Span ID: 8b560e2e7238eab5 |
| 237 | +Flags: 1 |
| 238 | +ResourceLog #1 |
| 239 | +Resource SchemaURL: |
| 240 | +Resource attributes: |
| 241 | + -> service.name: Str(basic-otlp-logging-example) |
| 242 | +ScopeLogs #0 |
| 243 | +ScopeLogs SchemaURL: |
| 244 | +InstrumentationScope opentelemetry-log-appender 0.1.0 |
| 245 | +LogRecord #0 |
| 246 | +ObservedTimestamp: 2023-09-08 21:50:35.872833713 +0000 UTC |
| 247 | +Timestamp: 1970-01-01 00:00:00 +0000 UTC |
| 248 | +SeverityText: INFO |
| 249 | +SeverityNumber: Info(9) |
| 250 | +Body: Str(hello from apple. My price is 1.99) |
| 251 | +Trace ID: |
| 252 | +Span ID: |
| 253 | +Flags: 0 |
| 254 | +``` |
0 commit comments