2.3 Sending data from the Agent to the Gateway
Verify the Start the Agent: In the Agent terminal window start the agent with the updated configuration: Verify CPU Metrics: At this stage, the Agent continues to collect CPU metrics once per hour or upon each restart and sends them to the gateway. The OpenTelemetry Collector, running in Gateway mode, processes these metrics and exports them to a file named Verify Data arrived at Gateway: Validate both collectors are running: Send a Test Trace: Below, we show the first and last lines of the debug output. Use the Complete Debug Output button below to verify that both the Agent and Gateway produced similar debug output. Gateway has handled the span: Verify that the gateway has generated a new file named Ensure that both In the provided
Exercise
gateway
is still running: Check your Gateway terminal window and make sure the Gateway collector is running.../otelcol --config=agent.yaml
<snip>
NumberDataPoints #37
Data point attributes:
-> cpu: Str(cpu9)
-> state: Str(system)
StartTimestamp: 2024-12-09 14:18:28 +0000 UTC
Timestamp: 2025-01-15 15:27:51.319526 +0000 UTC
Value: 9637.660000
./gateway-metrics.out
. This file stores the exported metrics as part of the pipeline service.gateway-metrics.out
file.resourceMetrics
section and the first set of CPU metrics — You will likely see more):{"resourceMetrics":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"YOUR_HOST_NAME"}},{"key":"os.type","value":{"stringValue":"YOUR_OS"}},{"key":"otelcol.service.mode","value":{"stringValue":"gateway"}}]},"scopeMetrics":[{"scope":{"name":"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper","version":"v0.116.0"},"metrics":[{"name":"system.cpu.time","description":"Total seconds each logical CPU spent on each mode.","unit":"s","sum":{"dataPoints":[{"attributes":[{"key":"cpu","value":{"stringValue":"cpu0"}},{"key":"state","value":{"stringValue":"user"}}],"startTimeUnixNano":"1733753908000000000","timeUnixNano":"1737133726158376000","asDouble":1168005.59}]}}]}]}]}
{
"resourceMetrics": [
{
"resource": {
"attributes": [
{
"key": "host.name",
"value": {
"stringValue": "YOUR_HOST_NAME"
}
},
{
"key": "os.type",
"value": {
"stringValue": "YOUR_OS"
}
},
{
"key": "otelcol.service.mode",
"value": {
"stringValue": "gateway"
}
}
]
},
"scopeMetrics": [
{
"scope": {
"name": "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper",
"version": "v0.116.0"
},
"metrics": [
{
"name": "system.cpu.time",
"description": "Total seconds each logical CPU spent on each mode.",
"unit": "s",
"sum": {
"dataPoints": [
{
"attributes": [
{
"key": "cpu",
"value": {
"stringValue": "cpu0"
}
},
{
"key": "state",
"value": {
"stringValue": "user"
}
}
],
"startTimeUnixNano": "1733753908000000000",
"timeUnixNano": "1737133726158376000",
"asDouble": 1168005.59
},
]
}
}
]
}
]
}
]
}
[WORKSHOP]/2-gateway
directory.trace.json
to the 2-gateway
directory.cURL
command to send the span.2025-02-05T15:55:18.966+0100 info Traces {"kind": "exporter", "data_type": "traces", "name": "debug", "resource spans": 1, "spans": 1}
<snip>
{"kind": "exporter", "data_type": "traces", "name": "debug"}
./gateway-traces.out
.{"resourceSpans":[{"resource":{"attributes":[{"key":"service.name","value":{"stringValue":"my.service"}},{"key":"deployment.environment","value":{"stringValue":"my.environment"}},{"key":"host.name","value":{"stringValue":"[YOUR_HOST_NAME]"}},{"key":"os.type","value":{"stringValue":"[YOUR_OS]"}},{"key":"otelcol.service.mode","value":{"stringValue":"agent"}}]},"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","kind":2,"startTimeUnixNano":"1544712660000000000","endTimeUnixNano":"1544712661000000000","attributes":[{"key":"user.name","value":{"stringValue":"George Lucas"}},{"key":"user.phone_number","value":{"stringValue":"+1555-867-5309"}},{"key":"user.email","value":{"stringValue":"george@deathstar.email"}},{"key":"user.account_password","value":{"stringValue":"LOTR\u003eStarWars1-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"}}],"status":{}}]}],"schemaUrl":"https://opentelemetry.io/schemas/1.6.1"}]}
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "service.name",
"value": {
"stringValue": "my.service"
}
},
{
"key": "deployment.environment",
"value": {
"stringValue": "my.environment"
}
},
{
"key": "host.name",
"value": {
"stringValue": "[YOUR_HOST_NAME]"
}
},
{
"key": "os.type",
"value": {
"stringValue": "[YOUR_OS]"
}
},
{
"key": "otelcol.service.mode",
"value": {
"stringValue": "agent"
}
}
]
},
"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",
"kind": 2,
"startTimeUnixNano": "1544712660000000000",
"endTimeUnixNano": "1544712661000000000",
"attributes": [
{
"key": "user.name",
"value": {
"stringValue": "George Lucas"
}
},
{
"key": "user.phone_number",
"value": {
"stringValue": "+1555-867-5309"
}
},
{
"key": "user.email",
"value": {
"stringValue": "george@deathstar.email"
}
},
{
"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"
}
}
],
"status": {}
}
]
}
],
"schemaUrl": "https://opentelemetry.io/schemas/1.6.1"
}
]
}
gateway-metrics.out
and gateway-traces.out
include a resource attribute key-value pair for otelcol.service.mode
with the value gateway
.
Note
gateway.yaml
configuration, we modified the resource/add_mode
processor to use the upsert
action instead of insert
.
The upsert
action updates the value of the resource attribute key if it already exists, setting it to gateway
. If the key is not present, the upsert
action will add it.
Stop the Agent and Gateway processes by pressing Ctrl-C
in their respective terminals.