diff --git a/terraform/modules/aws_ecs_service/container_definition.json b/terraform/modules/aws_ecs_service/container_definition.json index e4033b6..cc2bac6 100755 --- a/terraform/modules/aws_ecs_service/container_definition.json +++ b/terraform/modules/aws_ecs_service/container_definition.json @@ -38,7 +38,7 @@ %{ endif } %{ if use_adot_as_sidecar != "" } { - "name": "aws-otel-collector", + "name": "aws-otel-collector-${environment}", "cpu": 256, "memory": 512, "image": "amazon/aws-otel-collector", @@ -66,7 +66,7 @@ "mountPoints": [] }, { - "name": "aws-otel-emitter", + "name": "aws-otel-emitter-${environment}", "cpu": 256, "memory": 512, "image": "public.ecr.aws/aws-otel-test/aws-otel-goxray-sample-app:latest", @@ -74,7 +74,7 @@ "logConfiguration": { "logDriver": "awslogs", "options": { - "awslogs-group": "/ecs/ecs-aws-otel-sidecar-app", + "awslogs-group": "/ecs/ecs-aws-otel-sidecar-app-${environment}", "awslogs-region": "${region}", "awslogs-stream-prefix": "ecs", "awslogs-create-group": "True" @@ -82,7 +82,7 @@ }, "dependsOn": [ { - "containerName": "aws-otel-collector", + "containerName": "aws-otel-collector-${environment}", "condition": "START" } ], @@ -92,14 +92,14 @@ "mountPoints": [] }, { - "name": "nginx", + "name": "nginx-${environment}", "cpu": 256, "memory": 256, "image": "nginx:latest", "essential": false, "dependsOn": [ { - "containerName": "aws-otel-collector", + "containerName": "aws-otel-collector-${environment}", "condition": "START" } ], @@ -109,13 +109,13 @@ "mountPoints": [] }, { - "name": "aoc-statsd-emitter", + "name": "aoc-statsd-emitter-${environment}", "cpu": 256, "memory": 512, "image": "alpine/socat:latest", "dependsOn": [ { - "containerName": "aws-otel-collector", + "containerName": "aws-otel-collector-${environment}", "condition": "START" } ], @@ -125,7 +125,7 @@ "awslogs-create-group": "True", "awslogs-region": "${region}", "awslogs-stream-prefix": "ecs", - "awslogs-group": "/ecs/statsd-emitter" + "awslogs-group": "/ecs/statsd-emitter-${environment}" } }, "entryPoint": [ diff --git a/veda-wfs3-app/fast_api_main.py b/veda-wfs3-app/fast_api_main.py index ba844ce..ed72180 100644 --- a/veda-wfs3-app/fast_api_main.py +++ b/veda-wfs3-app/fast_api_main.py @@ -5,7 +5,7 @@ from fastapi import FastAPI, Request, Response, APIRouter from fastapi.routing import APIRoute -from opentelemetry import trace +from opentelemetry import trace, metrics from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor from starlette_cramjam.middleware import CompressionMiddleware from tipg.db import close_db_connection, connect_to_db, register_collection_catalog @@ -24,7 +24,10 @@ db_config = json.loads(json.loads(os.environ.get("DB_CONFIG"))) tracer = trace.get_tracer(__name__) - +meter = metrics.get_meter(__name__) +request_counter = meter.create_counter( + "request.counter", unit="1", description="counts the number of requests" +) class LoggerRouteHandler(APIRoute): @@ -37,6 +40,7 @@ async def route_handler(request: Request) -> Response: "route": self.path, "method": request.method, } + request_counter.add(1, ctx) with tracer.start_as_current_span("handle_request") as route_handler_span: route_handler_span.set_attribute("request.context.path", ctx["path"]) route_handler_span.set_attribute("request.context.route", ctx["route"])