|
| 1 | +--- |
| 2 | +title: 1.2 Test Agent Configuration |
| 3 | +linkTitle: 1.2 Test Agent Configuration |
| 4 | +weight: 2 |
| 5 | +--- |
| 6 | + |
| 7 | +Once you've updated the configuration, you’re ready to proceed to running the OpenTelemetry Collector with your new setup. This exercise sets the foundation for understanding how data flows through the OpenTelemetry Collector. |
| 8 | + |
| 9 | +{{% notice title="Exercise" style="green" icon="running" %}} |
| 10 | + |
| 11 | +**Find your Agent terminal window**: |
| 12 | + |
| 13 | +1. Change into the `[WORKSHOP]/1-agent` folder |
| 14 | +2. Run the following command: |
| 15 | + |
| 16 | +```sh { title="Agent" } |
| 17 | +../otelcol --config=agent.yaml |
| 18 | +``` |
| 19 | + |
| 20 | +In this workshop, we use **macOS/Linux** commands by default. If you’re using Windows, adjust the commands as needed i.e. use `./otelcol.exe`. |
| 21 | + |
| 22 | +{{% /notice %}} |
| 23 | + |
| 24 | +> [!note] |
| 25 | +> On Windows, a dialog box may appear asking if you want to grant public and private network access to `otelcol.exe`. Click **"Allow"** to proceed. |
| 26 | +
|
| 27 | +{{% notice title="Exercise" style="green" icon="running" %}} |
| 28 | + |
| 29 | +**Verify debug output**: If everything is set up correctly, the first and last lines of the output should display: |
| 30 | + |
| 31 | +```text |
| 32 | +2025/01/13T12:43:51 settings.go:478: Set config to [agent.yaml] |
| 33 | +<snip to the end> |
| 34 | +2025-01-13T12:43:51.747+0100 info [email protected]/service.go:261 Everything is ready. Begin running and processing data. |
| 35 | +``` |
| 36 | + |
| 37 | +**Create a test span file**: |
| 38 | +Instead of instrumenting an application, we will simulate sending trace data to the OpenTelemetry Collector using `cURL`. The trace data, formatted in JSON, represents what an instrumentation library would typically generate and send. |
| 39 | + |
| 40 | +1. Find your **Tests** Terminal window and change into the `[WORKSHOP]/1-agent` directory. |
| 41 | +2. Copy and paste the following **span** data into a new file named `trace.json`: |
| 42 | + |
| 43 | +This file will allow us to test how the OpenTelemetry Collector processes and send **spans** that are part of a trace, without requiring actual application instrumentation. |
| 44 | + |
| 45 | +{{% tabs %}} |
| 46 | +{{% tab title="trace.json" %}} |
| 47 | + |
| 48 | +```json |
| 49 | +{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"my.service"}},{"key":"deployment.environment","value":{"stringValue":"my.environment"}}]},"scopeSpans":[{"scope":{"name":"my.library","version":"1.0.0","attributes":[{"key":"my.scope.attribute","value":{"stringValue":"some scope attribute"}}]},"spans":[{"traceId":"5B8EFFF798038103D269B633813FC60C","spanId":"EEE19B7EC3C1B174","parentSpanId":"EEE19B7EC3C1B173","name":"I'm a server span","startTimeUnixNano":"1544712660000000000","endTimeUnixNano":"1544712661000000000","kind":2,"attributes":[{"key":"user.name","value":{"stringValue":"George Lucas"}},{"key":"user.phone_number","value":{"stringValue":"+1555-867-5309"}},{"key":"user.email","value":{"stringValue":" [email protected]"}},{"key":"user.account_password","value":{"stringValue":"LOTR>StarWars1-2-3"}},{"key":"user.visa","value":{"stringValue":"4111 1111 1111 1111"}},{"key":"user.amex","value":{"stringValue":"3782 822463 10005"}},{"key":"user.mastercard","value":{"stringValue":"5555 5555 5555 4444"}}]}]}]}]} |
| 50 | +``` |
| 51 | + |
| 52 | +{{% /tab %}} |
| 53 | +{{% /tabs %}} |
| 54 | + |
| 55 | +```text { title="Updated Directory Structure" } |
| 56 | +[WORKSHOP] |
| 57 | +├── 1-agent # Module directory |
| 58 | +│ └── agent.yaml # OpenTelemetry Collector configuration file |
| 59 | +│ └── trace.json # Sample trace data |
| 60 | +└── otelcol # OpenTelemetry Collector binary |
| 61 | +``` |
| 62 | + |
| 63 | +**Send a test span**: Run the following command to send a **span** to the agent: |
| 64 | + |
| 65 | +{{% tabs %}} |
| 66 | +{{% tab title="cURL Command" %}} |
| 67 | + |
| 68 | +```sh |
| 69 | + curl -X POST -i http://localhost:4318/v1/traces -H "Content-Type: application/json" -d "@trace.json" |
| 70 | +``` |
| 71 | + |
| 72 | +{{% /tab %}} |
| 73 | +{{% tab title="cURL Response" %}} |
| 74 | + |
| 75 | +```text |
| 76 | +HTTP/1.1 200 OK |
| 77 | +Content-Type: application/json |
| 78 | +Date: Mon, 27 Jan 2025 09:51:02 GMT |
| 79 | +Content-Length: 21 |
| 80 | +
|
| 81 | +{"partialSuccess":{}}% |
| 82 | + ``` |
| 83 | + |
| 84 | +{{% /tab %}} |
| 85 | +{{% /tabs %}} |
| 86 | + |
| 87 | +{{% notice info %}} |
| 88 | + |
| 89 | +1. `HTTP/1.1 200 OK`: Confirms the request was processed successfully. |
| 90 | +2. `{"partialSuccess":{}}`: Indicates 100% success, as the field is empty. In case of a partial failure, this field will include details about any failed parts. |
| 91 | + |
| 92 | +{{% /notice %}} |
| 93 | +{{% /notice %}} |
| 94 | + |
| 95 | +{{% notice note %}} |
| 96 | +On Windows, you may encounter the following error: |
| 97 | +{{% textcolor color="red" weight="bold" %}}Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" ...{{% /textcolor %}} |
| 98 | +To resolve this, use `curl.exe` instead of just `curl`. |
| 99 | +{{% /notice %}} |
| 100 | + |
| 101 | +{{% notice title="Exercise" style="green" icon="running" %}} |
| 102 | + |
| 103 | +**Verify Debug Output**: |
| 104 | + |
| 105 | +1. Find the **Agent** terminal window and check the collector's debug output. You should see the Debug entries related to the span you just sent. |
| 106 | +2. We are showing the first and last lines of the debug log for that span. To get the full context, Use the **Complete Debug Output** Button to review. |
| 107 | + |
| 108 | +```text |
| 109 | +2025-02-03T12:46:25.675+0100 info ResourceSpans #0 |
| 110 | +<snip> |
| 111 | + {"kind": "exporter", "data_type": "traces", "name": "debug"} |
| 112 | +``` |
| 113 | + |
| 114 | +{{% expand title="{{% badge style=primary icon=scroll %}}Complete Debug Output{{% /badge %}}" %}} |
| 115 | + |
| 116 | +```text |
| 117 | +2025-02-03T12:46:25.675+0100 info ResourceSpans #0 |
| 118 | +Resource SchemaURL: |
| 119 | +Resource attributes: |
| 120 | + -> service.name: Str(my.service) |
| 121 | + -> deployment.environment: Str(my.environment) |
| 122 | +ScopeSpans #0 |
| 123 | +ScopeSpans SchemaURL: |
| 124 | +InstrumentationScope my.library 1.0.0 |
| 125 | +InstrumentationScope attributes: |
| 126 | + -> my.scope.attribute: Str(some scope attribute) |
| 127 | +Span #0 |
| 128 | + Trace ID : 5b8efff798038103d269b633813fc60c |
| 129 | + Parent ID : eee19b7ec3c1b173 |
| 130 | + ID : eee19b7ec3c1b174 |
| 131 | + Name : I'm a server span |
| 132 | + Kind : Server |
| 133 | + Start time : 2018-12-13 14:51:00 +0000 UTC |
| 134 | + End time : 2018-12-13 14:51:01 +0000 UTC |
| 135 | + Status code : Unset |
| 136 | + Status message : |
| 137 | +Attributes: |
| 138 | + -> user.name: Str(George Lucas) |
| 139 | + -> user.phone_number: Str(+1555-867-5309) |
| 140 | + -> user.email: Str([email protected]) |
| 141 | + -> user.account_password: Str(LOTR>StarWars1-2-3) |
| 142 | + -> user.visa: Str(4111 1111 1111 1111) |
| 143 | + -> user.amex: Str(3782 822463 10005) |
| 144 | + -> user.mastercard: Str(5555 5555 5555 4444) |
| 145 | + {"kind": "exporter", "data_type": "traces", "name": "debug"} |
| 146 | +``` |
| 147 | + |
| 148 | +{{% /expand %}} |
| 149 | + |
| 150 | +{{% /notice %}} |
0 commit comments