Skip to content

Commit

Permalink
Merge pull request #749 from logzio/trace-context-jan13
Browse files Browse the repository at this point in the history
Trace context java
  • Loading branch information
Simplychee authored Jan 14, 2025
2 parents 3b6c7aa + 9ea8bbf commit ac51aad
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions docs/shipping/Code/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ For more details, see the [Log4j documentation](https://logging.apache.org/log4j
| **connectTimeoutMs** | *10 * 1000* | Connection timeout during log shipment, in milliseconds. | Required |
| **addHostname** | *false* | If true, adds a field named `hostname` with the machine's hostname. If there's no defined hostname, the field won't be added. | Required |
| **additionalFields** | *None* | Allows to add additional fields to the JSON message sent. The format is "fieldName1=fieldValue1;fieldName2=fieldValue2". Optionally, inject an environment variable value using this format: "fieldName1=fieldValue1;fieldName2=$ENV_VAR_NAME". The environment variable should be the only value. If the environment variable can't be resolved, the field will be omitted. | Optional |
| **addOpentelemetryContext** | Optional. Add `trace_id`, `span_id`, and `service_name` fields to logs when OpenTelemetry context is available. | `true` |
| **debug** | *false* | Boolean. Set to `true` to print debug messages to stdout. | Required |
| **compressRequests** | *false* | Boolean. If `true`, logs are compressed in gzip format before sending. If `false`, logs are sent uncompressed. | Required |
| **exceedMaxSizeAction** | *"cut"* | String. Use "cut" to truncate the message or "drop" to discard oversized logs. Logs exceeding the maximum size after truncation will be dropped. | Required |
Expand Down Expand Up @@ -260,6 +261,30 @@ Which produces the following output:
}
```

### Add OpenTelemetry context

If you're sending traces with OpenTelemetry instrumentation (auto or manual), you can correlate your logs with the trace context. This ensures your logs include trace data, such as service name, `span_id` and `trace_id` (version >= `2.2.0`).

This feature is enabled by default, To disable it, set the `addOpentelemetryContext` option in your configuration to `false`, like in this example:

```xml
<Appenders>
<LogzioAppender name="Logzio">
<logzioToken>your-logzio-personal-token-from-settings</logzioToken>
<logzioType>myAwesomeType</logzioType>
<logzioUrl>https://listener.logz.io:8071</logzioUrl>
<addOpentelemetryContext>false</addOpentelemetryContext>
</LogzioAppender>

</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Logzio"/>
</Root>
</Loggers>
```


</TabItem>
<TabItem value="Logzio-Logback-Appender" label="Logzio-Logback-Appender">

Expand Down Expand Up @@ -376,6 +401,7 @@ To output `debug` messages, add the parameter into the code:
| logzioType | The [log type](https://docs.logz.io/docs/user-guide/data-hub/log-parsing/default-parsing/#built-in-log-types), shipped as `type` field. Can't contain spaces. | `java` |
| addHostname | If true, adds a field named `hostname` with the machine's hostname. If there's no defined hostname, the field won't be added. | `false` |
| additionalFields | Adds fields to the JSON message output, formatted as `field1=value1;field2=value2`. Use `$` to inject an environment variable value, such as `field2=$VAR_NAME`. The environment variable should be the only value in the key-value pair. If the environment variable can't be resolved, the field is omitted. | N/A |
| addOpentelemetryContext | Optional. Add `trace_id`, `span_id`, and `service_name` fields to logs when OpenTelemetry context is available. | `true` |
| bufferDir | Filepath where the appender stores the buffer. | `System.getProperty("java.io.tmpdir")` |
| compressRequests | Boolean. If `true`, logs are compressed in gzip format before sending. If `false`, logs are sent uncompressed. | `false` |
| connectTimeout | Connection timeout during log shipment, in milliseconds. | `10 * 1000` |
Expand Down Expand Up @@ -465,6 +491,28 @@ Which produces this output:
"Your log message follows": "..."
}
```

### Add OpenTelemetry context

If you're sending traces with OpenTelemetry instrumentation (auto or manual), you can correlate your logs with the trace context. This ensures your logs include trace data, such as service name, `span_id` and `trace_id` (version >= `5.2.0`).

This feature is enabled by default, To disable it, set the `addOpentelemetryContext` option in your configuration to `false`, like in this example:

```xml
<configuration>
<appender name="LogzioLogbackAppender" class="io.logz.logback.LogzioLogbackAppender">
<token>yourlogziopersonaltokenfromsettings</token>
<logzioType>myAwesomeType</logzioType>
<logzioUrl>https://listener.logz.io:8071</logzioUrl>
<addOpentelemetryContext>false</addOpentelemetryContext>
</appender>
<root level="debug">
<!-- IMPORTANT: This line is required -->
<appender-ref ref="LogzioLogbackAppender"/>
</root>
</configuration>
```


#### Troubleshooting

Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/explore/trace-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Supported integrations for Trace context:
* [.NET](https://docs.logz.io/docs/shipping/Code/dotnet/#add-trace-context-1)
* [Python](https://docs.logz.io/docs/shipping/Code/Python/#trace-context)
* [Node.js](https://docs.logz.io/docs/shipping/code/node-js/)
* [Java](https://docs.logz.io/docs/shipping/code/java/#add-opentelemetry-context)

Additional integrations will be available in future updates.

Expand Down

0 comments on commit ac51aad

Please sign in to comment.