## Medplum Logs

Medplum server can stream the following to `STDOUT`

- Login Attempts
- Other troubleshooting information
- All RESTful interactions with FHIR resources, which are recorded as [FHIR AuditEvent resources](/content/docs/api/fhir/resources/auditevent/index.html)

### Warning

To capture [AuditEvent](/content/docs/api/fhir/resources/auditevent/index.html) resources for any RESTful interactions you **must** set the server configuration for [`logAuditEvents`](/content/docs/self-hosting/server-config#logauditevents/index.html)

For [batch requests](/content/docs/fhir-datastore/fhir-batch-requests/index.html) and [GraphQL queries](/content/docs/graphql/index.html), each individual read/search operation executed by the query generates its own log line. While these operations are logged separately, they all share the same [request ID / trace ID](/content/docs/integration/log-streaming#log-correlation/index.html) for easy correlation and tracing.

## Forwarding Logs via AWS Lambda

To forward logs from CloudWatch to external platforms, AWS Lambda functions are utilized. This involves creating Lambda functions that are triggered by new log entries in CloudWatch and are configured to push these logs to the chosen external logging system.

- For SumoLogic: [Setup Guide](https://help.sumologic.com/docs/send-data/collect-from-other-data-sources/amazon-cloudwatch-logs/)
- For DataDog: [Setup Guide](https://docs.datadoghq.com/logs/guide/send-aws-services-logs-with-the-datadog-lambda-function/?tab=awsconsole)
- For Splunk: [Setup Guide](https://www.splunk.com/en_us/blog/tips-and-tricks/how-to-easily-stream-aws-cloudwatch-logs-to-splunk.html)

## Log Correlation

Medplum uses includes both request IDs and trace IDs to aid in log correlation, enhancing debugging and monitoring capabilities.

The request ID is automatically generated by the Medplum server for each unique HTTP request.

Clients can pass in their own trace id in their request headers. Medplum supports both the headers `X-TRACE-ID` or [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header).

### Example: Adding a trace id to a medplum GET request
- Typescript
- cURL

```ts
await medplum.readResource('Patient', 'homer-simpson', {

headers: {

'X-TRACE-ID': 'MY-TRACE-ID',

},

});
```

```bash
curl https://api.medplum.com/fhir/R4/Patient/homer-simpson \

-H "Authorization: Bearer $TOKEN" \

-H "Content-Type: application/fhir+json" \

-H "X-TRACE-ID: "MY-TRACE-ID
```

- [Medplum Logs](/content/docs/integration/log-streaming#medplum-logs/index.html)
- [Forwarding Logs via AWS Lambda](/content/docs/integration/log-streaming#forwarding-logs-via-aws-lambda/index.html)
- [Log Correlation](/content/docs/integration/log-streaming#log-correlation/index.html)
