Skip to content

Add File and OS Information#

It is usually important to know where the log lines are coming from. This helps fault domain isolation and enables quickly routing the problem to the relevant owner / team.

In this scenario, the collector will be used to enrich the log lines to include the following information on each log line:

  • Hostname
  • Operating system type
  • Log file name
  • Log file path

scenario2.yaml shows the OpenTelemetry collector configuration to achieve this.

Stop Previous Collector#

If you haven't done so already, stop the previous collector process by pressing Ctrl + C.

Start Collector#

Run the following command to start the collector:

/workspaces/$RepositoryName/dynatrace-otel-collector --config=/workspaces/$RepositoryName/scenario2.yaml

Generate Log Data#

Open file.log file and add this line then save the file.

My second dummy log line...

Verify Debug Data in Collector Output#

View the collector terminal window and verify that the filelog receiver has sent the data to the collector. You should see terminal output like this:

...
2025-03-27T06:04:05.900Z        info    ResourceLog #0
Resource SchemaURL: https://opentelemetry.io/schemas/1.6.1
Resource attributes:
     -> host.name: Str(codespaces-3655f4)
     -> os.type: Str(linux)
...
Body: Str(My second dummy log line...)
Attributes:
     -> log.file.name: Str(file.log)
     -> log.file.path: Str(/workspaces/demo-opentelemetry-patterns/file.log)

Notice that host.name and os.type have been added as resource attributes. The collector performed this lookup and attached them automatically. Notice too that the log record has new attributes of log.file.name and log.file.path.

View Data in Dynatrace#

Tip

Right click and "open image in new tab" to see large image

scenario2 dynatrace results

Click the Run button again on the DQL tile. You should see the new data.

Reminder, the DQL statement is:

fetch logs
| filter contains(content, "dummy log line")

Congratulations! The log lines are now automatically enriched with important host-level information.