---
title: Correlate Logs and Tests
description: Correlate your logs with your test traces.
breadcrumbs: Docs > Test Optimization in Datadog > Correlate Logs and Tests
---

# Correlate Logs and Tests

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Overview{% #overview %}

You can correlate Test Optimization data with [logs injected into Datadog](https://docs.datadoghq.com/logs/log_collection/), which allows you to view and analyze logs for specific test cases.

{% image
   source="https://docs.dd-static.net/images/continuous_integration/correlate_logs_and_tests.4b40b14c588a6ad4d595778ec376cdca.png?auto=format"
   alt="Examine logs for specific test cases with logs and tests correlation." /%}

## Setup{% #setup %}

Correlation can be configured differently depending on how you [send your tests data to Datadog](https://docs.datadoghq.com/tests/setup/).

{% tab title="Cloud CI provider (Agentless)" %}
### Java{% #java %}

Agentless log submission is supported for the following languages and frameworks:

- `dd-trace-java >= 1.35.2` and Log4j2.

Use the following environment variables to enable and configure Agentless log submission:

| Name                                                | Description                                 | Default value |
| --------------------------------------------------- | ------------------------------------------- | ------------- |
| `DD_AGENTLESS_LOG_SUBMISSION_ENABLED` (required)    | Enables/disables log submission             | `false`       |
| `DD_AGENTLESS_LOG_SUBMISSION_LEVEL` (optional)      | Sets log level for Agentless submission     | `INFO`        |
| `DD_AGENTLESS_LOG_SUBMISSION_QUEUE_SIZE` (optional) | Sets the maximum size of pending logs queue | `1024`        |
| `DD_AGENTLESS_LOG_SUBMISSION_URL` (optional)        | Sets custom URL for submitting logs         | -             |

### Javascript/Typescript{% #javascripttypescript %}

Agentless log submission is supported for the following languages and frameworks:

- `dd-trace-js >= 5.24.0` and `dd-trace-js >= 4.48.0` and `winston`.

Use the following environment variables to enable and configure Agentless log submission:

| Name                                             | Description                         | Default value |
| ------------------------------------------------ | ----------------------------------- | ------------- |
| `DD_AGENTLESS_LOG_SUBMISSION_ENABLED` (required) | Enables/disables log submission     | `false`       |
| `DD_AGENTLESS_LOG_SUBMISSION_URL` (optional)     | Sets custom URL for submitting logs | -             |

### .NET{% #net %}

Agentless log submission is supported for the following languages and frameworks:

- `dd-trace-dotnet >= 2.50.0` and XUnit TestOutputHelper.

Use the following environment variables to enable and configure Agentless log submission:

| Name                                      | Description                                   | Default value |
| ----------------------------------------- | --------------------------------------------- | ------------- |
| `DD_CIVISIBILITY_LOGS_ENABLED` (required) | Enables/disables CI Visibility log submission | `false`       |

### Swift{% #swift %}

Use the following environment variables to enable and configure log submission:

| Name                               | Description                            | Default value |
| ---------------------------------- | -------------------------------------- | ------------- |
| `DD_ENABLE_STDOUT_INSTRUMENTATION` | Enables/disables stdout log submission | `false`       |
| `DD_ENABLE_STDERR_INSTRUMENTATION` | Enables/disables stderr log submission | `false`       |

### Ruby{% #ruby %}

Agentless logs submission with Test Optimization is supported for Rails applications. Before enabling, ensure that your application is [instrumented with Datadog tracing](https://docs.datadoghq.com/tracing/trace_collection/automatic_instrumentation/dd_libraries/ruby/#rails-or-hanami-applications).

To use agentless log submission, you need `datadog-ci` version `0.16` or later. The following logging libraries are supported:

- `activesupport >= 5.0` (only when using `ActiveSupport::TaggedLogging`)
- `lograge >= 0.14`
- `semantic_logger >= 4.0`

Use the following environment variable to enable log submission:

| Name                                             | Description                     | Default value |
| ------------------------------------------------ | ------------------------------- | ------------- |
| `DD_AGENTLESS_LOG_SUBMISSION_ENABLED` (required) | Enables/disables log submission | `false`       |

{% /tab %}

{% tab title="On-Premises CI provider (Datadog Agent)" %}

1. [Set up log collection](https://docs.datadoghq.com/logs/log_collection/) through the Datadog Agent.
1. Follow the steps described in [Correlate Logs and Traces](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/).

{% /tab %}

## Further Reading{% #further-reading %}

- [Learn about Test Optimization](https://docs.datadoghq.com/tests)
