Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(otel): adding in basic tracing via otel #794

Merged
merged 15 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,25 @@ services:
retries: 30
ports:
- '9090:9090'

otlpcollector:
image: grafana/otel-lgtm
ports:
# there are lots more ports available, but these are the only one's
# currently being used
- 4317:4317 # OTLP gRPC receiver
- 4318:4318 # OTLP http receiver
- 3000:3000 # Grafana

# Uncomment this if you want to run the collector locally and send to GCP instead of the one used for local development
# Make sure to have a service json in GOOGLE_APPLICATION_CREDENTIALS_JSON in the .env file
# otlpcollector:
# image: pocket/opentelemetry-collector-contrib
# env_file:
# - .env
# ports:
# # there are lots more ports available, but these are the only one's
# # currently being used
# - 4317:4317 # OTLP gRPC receiver
# - 4318:4318 # OTLP http receiver
# - 3000:3000 # Grafana
14 changes: 14 additions & 0 deletions images/otel/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM alpine:latest

COPY --from=otel/opentelemetry-collector-contrib:latest /otelcol-contrib /otelcol-contrib

COPY otel-collector-config.yaml /etc/otelcol-contrib/config.yaml
COPY entrypont.sh /entrypont.sh
RUN chmod a+x /entrypont.sh

ENV GOOGLE_APPLICATION_CREDENTIALS=/etc/otelcol-contrib/key.json
WORKDIR /

ENTRYPOINT [ "./entrypont.sh" ]

CMD [ "/otelcol-contrib", "--config", "/etc/otelcol-contrib/config.yaml" ]
4 changes: 4 additions & 0 deletions images/otel/entrypont.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
echo "$GOOGLE_APPLICATION_CREDENTIALS_JSON" > /etc/otelcol-contrib/key.json
exec "$@"
59 changes: 59 additions & 0 deletions images/otel/otel-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Note this is only built nightly and will take effect on the next deploy after being built.
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317" # gRPC port for receiving traces, metrics, and logs over gRPC
http:
endpoint: "0.0.0.0:4318" # http port for receiving traces, metrics, and logs over http
exporters:
googlecloud:
log:
default_log_name: opentelemetry.io/collector-exported-log
# debug:
# verbosity: detailed
processors:
memory_limiter:
check_interval: 1s
limit_percentage: 65
spike_limit_percentage: 20
batch:
# batch metrics before sending to reduce API usage
send_batch_max_size: 200
send_batch_size: 200
timeout: 5s
resourcedetection/ecs:
detectors: [env, ecs]
timeout: 2s
override: false
resource/cleanup_for_google:
attributes:
- key: service.namespace
value: pocket
action: insert
# We must set the region to us-east1, as the google exporter uses this to know where to send data to.
- key: cloud.region
value: us-east1
action: upsert
- key: cloud.availability_zone
value: us-east1-b
action: upsert
# set this to the ecs task id
- key: host.id
from_attribute: aws.ecs.task.id
action: upsert

service:
pipelines:
traces:
receivers: [otlp]
processors: [resourcedetection/ecs, resource/cleanup_for_google, memory_limiter, batch]
exporters: [googlecloud]
metrics:
receivers: [otlp]
processors: [resourcedetection/ecs, resource/cleanup_for_google, memory_limiter, batch]
exporters: [googlecloud]
logs:
receivers: [otlp]
processors: [resourcedetection/ecs, resource/cleanup_for_google, memory_limiter, batch]
exporters: [googlecloud]
42 changes: 29 additions & 13 deletions infrastructure/client-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,34 @@ class ClientAPI extends TerraformStack {
startPeriod: 0,
},
},
{
name: 'otel-collector',
containerImage: 'pocket/opentelemetry-collector-contrib',
essential: true,
logMultilinePattern: '^\\S.+',
logGroup: this.createCustomLogGroup('otel-collector'),
portMappings: [
{
hostPort: 4138,
containerPort: 4138,
},
{
hostPort: 4137,
containerPort: 4137,
},
{
hostPort: 55681,
containerPort: 55681,
},
],
secretEnvVars: [
{
name: 'GOOGLE_APPLICATION_CREDENTIALS_JSON',
valueFrom: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/GCP_SA_TRACES:::`,
},
],
repositoryCredentialsParam: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/DockerHub`,
},
],
codeDeploy: {
useCodeDeploy: true,
Expand Down Expand Up @@ -309,19 +337,7 @@ class ClientAPI extends TerraformStack {
effect: 'Allow',
},
],
taskRolePolicyStatements: [
{
actions: [
'xray:PutTraceSegments',
'xray:PutTelemetryRecords',
'xray:GetSamplingRules',
'xray:GetSamplingTargets',
'xray:GetSamplingStatisticSummaries',
],
resources: ['*'],
effect: 'Allow',
},
],
taskRolePolicyStatements: [],
taskExecutionDefaultAttachmentArn:
'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy',
},
Expand Down
33 changes: 28 additions & 5 deletions infrastructure/list-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,34 @@ class ListAPI extends TerraformStack {
logGroup: this.createCustomLogGroup('app'),
logMultilinePattern: '^\\S.+',
},
{
name: 'otel-collector',
containerImage: 'pocket/opentelemetry-collector-contrib',
essential: true,
logMultilinePattern: '^\\S.+',
logGroup: this.createCustomLogGroup('otel-collector'),
portMappings: [
{
hostPort: 4138,
containerPort: 4138,
},
{
hostPort: 4137,
containerPort: 4137,
},
{
hostPort: 55681,
containerPort: 55681,
},
],
secretEnvVars: [
{
name: 'GOOGLE_APPLICATION_CREDENTIALS_JSON',
valueFrom: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/GCP_SA_TRACES:::`,
},
],
repositoryCredentialsParam: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/DockerHub`,
},
],
codeDeploy: {
useCodeDeploy: true,
Expand Down Expand Up @@ -349,11 +377,6 @@ class ListAPI extends TerraformStack {
'logs:CreateLogStream',
'logs:DescribeLogStreams',
'logs:DescribeLogGroups',
'xray:PutTraceSegments',
'xray:PutTelemetryRecords',
'xray:GetSamplingRules',
'xray:GetSamplingTargets',
'xray:GetSamplingStatisticSummaries',
],
resources: ['*'],
effect: 'Allow',
Expand Down
33 changes: 28 additions & 5 deletions infrastructure/parser-graphql-wrapper/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,34 @@ class ParserGraphQLWrapper extends TerraformStack {
},
],
},
{
name: 'otel-collector',
containerImage: 'pocket/opentelemetry-collector-contrib',
essential: true,
logMultilinePattern: '^\\S.+',
logGroup: this.createCustomLogGroup('otel-collector'),
portMappings: [
{
hostPort: 4138,
containerPort: 4138,
},
{
hostPort: 4137,
containerPort: 4137,
},
{
hostPort: 55681,
containerPort: 55681,
},
],
secretEnvVars: [
{
name: 'GOOGLE_APPLICATION_CREDENTIALS_JSON',
valueFrom: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/GCP_SA_TRACES`,
},
],
repositoryCredentialsParam: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/DockerHub`,
},
],
codeDeploy: {
useCodeDeploy: true,
Expand Down Expand Up @@ -326,11 +354,6 @@ class ParserGraphQLWrapper extends TerraformStack {
'logs:CreateLogStream',
'logs:DescribeLogStreams',
'logs:DescribeLogGroups',
'xray:PutTraceSegments',
'xray:PutTelemetryRecords',
'xray:GetSamplingRules',
'xray:GetSamplingTargets',
'xray:GetSamplingStatisticSummaries',
],
resources: ['*'],
effect: 'Allow',
Expand Down
38 changes: 38 additions & 0 deletions infrastructure/user-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,46 @@ class UserAPI extends TerraformStack {
name: 'SALT_2',
valueFrom: `${intMaskSecretArn}:salt2::`,
},
{
name: 'UNLEASH_ENDPOINT',
valueFrom: `arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Shared/${config.environment}/UNLEASH_ENDPOINT`,
},
{
name: 'UNLEASH_KEY',
valueFrom: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:${config.name}/${config.environment}/UNLEASH_KEY`,
},
],
logGroup: this.createCustomLogGroup('app'),
logMultilinePattern: '^\\S.+',
},
{
name: 'otel-collector',
containerImage: 'pocket/opentelemetry-collector-contrib',
essential: true,
logMultilinePattern: '^\\S.+',
logGroup: this.createCustomLogGroup('otel-collector'),
portMappings: [
{
hostPort: 4138,
containerPort: 4138,
},
{
hostPort: 4137,
containerPort: 4137,
},
{
hostPort: 55681,
containerPort: 55681,
},
],
secretEnvVars: [
{
name: 'GOOGLE_APPLICATION_CREDENTIALS_JSON',
valueFrom: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/GCP_SA_TRACES:::`,
},
],
repositoryCredentialsParam: `arn:aws:secretsmanager:${region.name}:${caller.accountId}:secret:Shared/DockerHub`,
},
],
codeDeploy: {
useCodeDeploy: true,
Expand Down Expand Up @@ -232,6 +268,8 @@ class UserAPI extends TerraformStack {
resources: [
`arn:aws:ssm:${region.name}:${caller.accountId}:parameter/${config.name}/${config.environment}`,
`arn:aws:ssm:${region.name}:${caller.accountId}:parameter/${config.name}/${config.environment}/*`,
`arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Shared/${config.environment}/*`,
`arn:aws:ssm:${region.name}:${caller.accountId}:parameter/Shared/${config.environment}`,
],
effect: 'Allow',
},
Expand Down
16 changes: 11 additions & 5 deletions infrastructure/user-list-search/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ module "otel" {
version = "0.61.1"

essential = true
container_name = "aws-otel-collector"
container_image = "amazon/aws-otel-collector"
command = [
"--config=/etc/ecs/ecs-xray.yaml",
]
container_name = "otel-collector"
container_image = "pocket/opentelemetry-collector-contrib"

repository_credentials = {
credentialsParameter : local.container_credential
Expand All @@ -131,6 +128,11 @@ module "otel" {
}
}

secrets = [{
name = "GOOGLE_APPLICATION_CREDENTIALS_JSON"
valueFrom = "${local.secret_path_shared}GCP_SA_TRACES:::"
}]

port_mappings = [
{
containerPort = 4138
Expand All @@ -139,6 +141,10 @@ module "otel" {
{
containerPort = 4137
hostPort = 4137
},
{
containerPort = 55681
hostPort = 55681
}
]
container_cpu = null
Expand Down
1 change: 1 addition & 0 deletions infrastructure/user-list-search/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locals {
}
private_subnet_ids = split(",", data.aws_ssm_parameter.private_subnets.value)
secret_path = "arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:${local.name}/${local.env}/"
secret_path_shared = "arn:aws:secretsmanager:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:secret:Shared/"
ssm_path = "arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter/${local.name}/${local.env}/"
ssm_path_shared = "arn:aws:ssm:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:parameter/Shared/${local.env}/"

Expand Down
Loading
Loading