|
| 1 | +--- |
| 2 | +title: Initial setup our agent config |
| 3 | +linkTitle: 1 - Agent Setup |
| 4 | +time: 10 minutes |
| 5 | +weight: 10 |
| 6 | +--- |
| 7 | + |
| 8 | +Pick a location where you are going to run the workshop on your machine, (we will use [WORKSHOP] for this location), create a sub directory called **1-agent** and move into it. |
| 9 | + |
| 10 | +In *[WORKSHOP]/1-agent* create a file called **agent.yaml** and copy the following starting config in it. |
| 11 | + |
| 12 | +``` text |
| 13 | +receivers: |
| 14 | +
|
| 15 | +exporters: |
| 16 | + |
| 17 | +processors: |
| 18 | + memory_limiter: |
| 19 | + check_interval: 2s |
| 20 | + limit_mib: 512 |
| 21 | + |
| 22 | +service: |
| 23 | + pipelines: |
| 24 | + traces: |
| 25 | + metrics: |
| 26 | + logs: |
| 27 | +``` |
| 28 | + |
| 29 | +Let's start with our first exercise: |
| 30 | + |
| 31 | +{{% notice title="Exercise" style="green" icon="running" %}} |
| 32 | + |
| 33 | +* Add an **otlp** receiver, under the *protocols* section, add a *HTTP* entry, with an endpoint of *"0.0.0.0:4318"* and add it to all the pipelines |
| 34 | +* Add a **debug** exporter with *verbosity* entry set to *detailed* and also add it to all the pipelines |
| 35 | + |
| 36 | +{{% /notice %}} |
| 37 | + |
| 38 | +{{% notice title="Tip" style="primary" icon="lightbulb" %}} |
| 39 | + Note that in the exercise above all key elements are highlighted, you just need to add them yourself. |
| 40 | + Pay attention to the format as the configuration of the agent is using yaml based. |
| 41 | + |
| 42 | +{{% /notice %}} |
| 43 | + |
| 44 | +if you use [https://www.otelbin.io/](https://www.otelbin.io/) to validate your agent.yaml your configuration should look like this: |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +--- |
| 49 | +Run the following command to test your config (make sure you use the right otel collector you downloaded): |
| 50 | + |
| 51 | +```text |
| 52 | +[LOCATION_OF_OTELCOLLECTOR]/otelcol_darwin_arm64 --config=agent.yaml |
| 53 | +``` |
| 54 | + |
| 55 | +If you have done everything correctly the last line of the out put should be : |
| 56 | + |
| 57 | +```text |
| 58 | +2025-01-13T12:43:51.747+0100 info [email protected]/service.go:261 Everything is ready. Begin running and processing data. |
| 59 | +``` |
| 60 | + |
| 61 | +Now start a new shell and create a file called **trace.json* and copy the following content: |
| 62 | + |
| 63 | +```text |
| 64 | +{ |
| 65 | + "resourceSpans": [ |
| 66 | + { |
| 67 | + "resource": { |
| 68 | + "attributes": [ |
| 69 | + { |
| 70 | + "key": "service.name", |
| 71 | + "value": { |
| 72 | + "stringValue": "my.service" |
| 73 | + } |
| 74 | + }, |
| 75 | + { |
| 76 | + "key": "deployment.environment", |
| 77 | + "value": { |
| 78 | + "stringValue": "my.environment" |
| 79 | + } |
| 80 | + } |
| 81 | + ] |
| 82 | + }, |
| 83 | + "scopeSpans": [ |
| 84 | + { |
| 85 | + "scope": { |
| 86 | + "name": "my.library", |
| 87 | + "version": "1.0.0", |
| 88 | + "attributes": [ |
| 89 | + { |
| 90 | + "key": "my.scope.attribute", |
| 91 | + "value": { |
| 92 | + "stringValue": "some scope attribute" |
| 93 | + } |
| 94 | + } |
| 95 | + ] |
| 96 | + }, |
| 97 | + "spans": [ |
| 98 | + { |
| 99 | + "traceId": "5B8EFFF798038103D269B633813FC60C", |
| 100 | + "spanId": "EEE19B7EC3C1B174", |
| 101 | + "parentSpanId": "EEE19B7EC3C1B173", |
| 102 | + "name": "I'm a server span", |
| 103 | + "startTimeUnixNano": "1544712660000000000", |
| 104 | + "endTimeUnixNano": "1544712661000000000", |
| 105 | + "kind": 2, |
| 106 | + "attributes": [ |
| 107 | + { |
| 108 | + "keytest": "my.span.attr", |
| 109 | + "value": { |
| 110 | + "stringValue": "some value" |
| 111 | + } |
| 112 | + } |
| 113 | + ] |
| 114 | + } |
| 115 | + ] |
| 116 | + } |
| 117 | + ] |
| 118 | + } |
| 119 | + ] |
| 120 | + } |
| 121 | +
|
| 122 | +``` |
| 123 | + |
| 124 | +In the second Shell, run the following command to test your setup: |
| 125 | + |
| 126 | +```text |
| 127 | +curl -X POST -i http://localhost:4318/v1/traces \ |
| 128 | +-H "Content-Type: application/json" \ |
| 129 | + -d @trace.json |
| 130 | +``` |
| 131 | + |
| 132 | +Your collector should show the following output: |
| 133 | + |
| 134 | + ```text |
| 135 | + 2025-01-13T13:26:13.502+0100 info Traces {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 1} |
| 136 | +2025-01-13T13:26:13.502+0100 info ResourceSpans #0 |
| 137 | +Resource SchemaURL: |
| 138 | +Resource attributes: |
| 139 | + -> service.name: Str(my.service) |
| 140 | + -> deployment.environment: Str(my.environment) |
| 141 | +ScopeSpans #0 |
| 142 | +ScopeSpans SchemaURL: |
| 143 | +InstrumentationScope my.library 1.0.0 |
| 144 | +InstrumentationScope attributes: |
| 145 | + -> my.scope.attribute: Str(some scope attribute) |
| 146 | +Span #0 |
| 147 | + Trace ID : 5b8efff798038103d269b633813fc60c |
| 148 | + Parent ID : eee19b7ec3c1b173 |
| 149 | + ID : eee19b7ec3c1b174 |
| 150 | + Name : I'm a server span |
| 151 | + Kind : Server |
| 152 | + Start time : 2018-12-13 14:51:00 +0000 UTC |
| 153 | + End time : 2018-12-13 14:51:01 +0000 UTC |
| 154 | + Status code : Unset |
| 155 | + Status message : |
| 156 | +Attributes: |
| 157 | + -> : Str(some value) |
| 158 | + {"kind": "exporter", "data_type": "traces", "name": "debug"} |
| 159 | +``` |
| 160 | + |
| 161 | +Let's move on to adding a file exporter to use that to mimic a backend |
0 commit comments