Skip to content

Commit

Permalink
Merge pull request #722 from logzio/docs/update-go-layer
Browse files Browse the repository at this point in the history
Updated env variable and ARN layer
  • Loading branch information
Simplychee authored Dec 10, 2024
2 parents 29331b2 + 99fddbe commit a6bb760
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 178 deletions.
168 changes: 0 additions & 168 deletions docs/shipping/AWS/aws-lambda-extension-go.md

This file was deleted.

172 changes: 163 additions & 9 deletions docs/shipping/Code/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
id: GO
title: GO
overview: Send logs, metrics and traces from you Go code
product: ['logs','metrics','tracing']
os: ['windows', 'linux']
filters: ['Code']
recommendedFor: ['Software Engineer']
product: ["logs","metrics","tracing"]
os: ["windows", "linux"]
filters: ["Code", "AWS", "Compute"]
recommendedFor: ["Software Engineer"]
logo: https://logzbucket.s3.eu-west-1.amazonaws.com/logz-docs/shipper-logos/go.svg
logs_dashboards: []
logs_alerts: []
logs2metrics: []
metrics_dashboards: ['2cm0FZu4VK4vzH0We6SrJb']
metrics_alerts: ['1UqjU2gqNAKht1f62jBC9Q']
metrics_dashboards: ["2cm0FZu4VK4vzH0We6SrJb"]
metrics_alerts: ["1UqjU2gqNAKht1f62jBC9Q"]
drop_filter: []
---

Expand Down Expand Up @@ -502,10 +502,11 @@ Encounter an issue? See our [log shipping troubleshooting](https://docs.logz.io/
</TabItem>
</Tabs>



## Traces

<Tabs>
<TabItem value="opentelemetry" label="OpenTelemetry" default>

Deploy this integration to enable instrumentation of your Go application using OpenTelemetry.

### Manual configuration
Expand Down Expand Up @@ -711,5 +712,158 @@ go run <YOUR-APPLICATION-FILE-NAME>.go
Give your traces some time to get from your system to ours, and then open [Tracing](https://app.logz.io/#/dashboard/jaeger).
</TabItem>
<TabItem value="lambda-otel" label="Lambda via OpenTelemetry">
Deploy this integration to instrument your Go application running on AWS Lambda and send the traces to your Logz.io account. This is done by adding a dedicated layer for OpenTelemetry collector and configuring environment variables of these layer.
:::note
This integration only works for the following AWS regions: `us-east-1`, `us-east-2`, `us-west-1`, `us-west-2`,
`ap-south-1`, `ap-northeast-3`, `ap-northeast-2`, `ap-southeast-1`, `ap-southeast-2`, `ap-northeast-1`,
`eu-central-1`, `eu-west-1`, `eu-west-2`, `eu-west-3`, `eu-north-1`,
`sa-east-1`,
`ca-central-1`.
:::
**Before you begin, you'll need**:
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html)
- Configured [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html)
- A Lambda function with Go application.
:::note
Using `aws lambda update-function-configuration` with `--layers` replaces all existing layers with the specified ARN(s). To add a new layer without removing existing ones, include all desired layer ARNs in the command, both new and previously attached.
:::
:::note
Adding environmental variables using the AWS CLI commands below, will overwrite all existing variables for your Lambda function.
:::
:::note
This integration uses OpenTelemetry Collector Contrib, not the OpenTelemetry Collector Core.
:::
#### Add the OpenTelemetry collector layer to your Lambda function
This layer contains the OpenTelemetry collector that will capture data from your application.
```shell
aws lambda update-function-configuration --function-name <<YOUR-LAMBDA_FUNCTION_NAME>> --layers arn:aws:lambda:<<YOUR-AWS-REGION>>:486140753397:layer:logzio-opentelemetry-collector-<<ARCHITECHTURE>>:<<VERSION>>
```
Replace `<<YOUR-LAMBDA_FUNCTION_NAME>>` with the name of your Lambda function running the Java application.
Replace `<<YOUR-AWS-REGION>>` with the code of your AWS regions, e.g. `us-east-1`.
Replace `<<ARCHITECTURE>>` with the target architecture for your Lambda function, either `arm64` for ARM-based applications or `amd64` (also known as x86_64) for traditional 64-bit Intel/AMD applications.
Replace `<<VERSION>>` with the latest version of the layer. You can find the latest version number by visiting the [Logz.io OpenTelemetry Lambda Releases page.](https://github.com/logzio/opentelemetry-lambda/releases)
#### Create a configuration file for the OpenTelemetry collector
By default, the OpenTelemetry collector layer exports data to the Lambda console. To customize the collector configuration, you need to add a `collector.yaml` to your function and specifiy its location via the `OPENTELEMETRY_COLLECTOR_CONFIG_URI` environment variable.
The `collector.yaml` file will have the following configuration:
```yaml
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
http:
endpoint: "0.0.0.0:4318"

exporters:
logzio/traces:
account_token: "<<TRACING-SHIPPING-TOKEN>>"
region: "<<LOGZIO_ACCOUNT_REGION_CODE>>"

service:
pipelines:
traces:
receivers: [otlp]
exporters: [logzio/traces]
```
{@include: ../../_include/tracing-shipping/replace-tracing-token.html}
{@include: ../../_include/tracing-shipping/tail-sampling.md}
#### Direct the OpenTelemetry collector to the configuration file
Add `OPENTELEMETRY_COLLECTOR_CONFIG_URI` variable to direct the OpenTelemetry collector to the configuration file:
```shell
aws lambda update-function-configuration --function-name <<YOUR-LAMBDA_FUNCTION_NAME>> --environment Variables={OPENTELEMETRY_COLLECTOR_CONFIG_URI=<<PATH_TO_YOUR_COLLECTOR.YAML>>}
```
Replace `<<YOUR-LAMBDA_FUNCTION_NAME>>` with the name of your Lambda function running the Go application.
Replace `<<PATH_TO_YOUR_COLLECTOR.YAML>>` with the actual path to your `collector.yaml` file.
(If `collector.yaml` is located in the root directory of your application, use the path `/var/task/collector.yaml`.)
#### Activate tracing for your Lambda function
```shell
aws lambda update-function-configuration --function-name <<YOUR-LAMBDA_FUNCTION_NAME>> --tracing-config Mode=Active
```
Replace `<<YOUR-LAMBDA_FUNCTION_NAME>>` with the name of your Lambda function running the Go application.
## Example: Manual Instrumentation for Go Lambda Functions
Below is a simple example that demonstrates how to instrument a Go-based AWS Lambda function using OpenTelemetry:
```go
package main

import (
"context"
"github.com/aws/aws-lambda-go/lambda"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"log"
)

// handler is your Lambda function handler
func handler(ctx context.Context, event any) (string, error) {
log.Println("Starting function")
// Configure the OTLP exporter to send traces to an OpenTelemetry Collector
exporter, err := otlptrace.New(ctx, otlptracegrpc.NewClient(
otlptracegrpc.WithEndpoint("localhost:4317"), // Replace with your collector endpoint
otlptracegrpc.WithInsecure(),
))
if err != nil {
log.Fatalf("Failed to create OTLP trace exporter: %v", err)
}

// Set up a trace provider with a batch span processor and the OTLP exporter
tp := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
)
otel.SetTracerProvider(tp)
// Create a tracer
tracer := tp.Tracer("example-tracer")

// Start a span
_, span := tracer.Start(ctx, "lambda-example-span")
// Your Lambda logic here
log.Println("Handling event", span)
span.End()
tp.ForceFlush(ctx)
return "Event handled successfully", nil
}

func main() {
lambda.Start(handler)
}
```
This example manually sets up OpenTelemetry tracing within a Go Lambda function, configuring the OTLP exporter to send traces to an OpenTelemetry Collector. Remember to replace `localhost:4317` with the actual endpoint of your collector.
For additional information and best practices on instrumenting your Go applications with OpenTelemetry, refer to the [OpenTelemetry Go documentation](https://opentelemetry.io/docs/languages/go/instrumentation/#traces)
</TabItem>
</Tabs>
1 change: 1 addition & 0 deletions static/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
/docs/user-guide/cloud-siem/integrations/siemplify/ /docs/cloud-siem/integrations/siemplify/
/docs/user-guide/cloud-siem/integrations/xsoar-integration/ /docs/cloud-siem/integrations/xsoar-integration/
/docs/user-guide/integrations/terraform/ /docs/integrations/terraform/
/docs/shipping/aws/lambda-extension-go/ /docs/shipping/code/go/#traces
# Shippers
/shipping/ /docs/category/send-your-data/
/user-guide/log-shipping/ /docs/category/send-your-data/
Expand Down
2 changes: 1 addition & 1 deletion static/manifest.json

Large diffs are not rendered by default.

0 comments on commit a6bb760

Please sign in to comment.