Skip to content

Commit

Permalink
add counter for custom request metric
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchodeluxe committed Mar 6, 2023
1 parent 4947eeb commit fd2fc62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
18 changes: 9 additions & 9 deletions terraform/modules/aws_ecs_service/container_definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -66,23 +66,23 @@
"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",
"essential": false,
"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"
}
},
"dependsOn": [
{
"containerName": "aws-otel-collector",
"containerName": "aws-otel-collector-${environment}",
"condition": "START"
}
],
Expand All @@ -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"
}
],
Expand All @@ -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"
}
],
Expand All @@ -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": [
Expand Down
8 changes: 6 additions & 2 deletions veda-wfs3-app/fast_api_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):

Expand All @@ -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"])
Expand Down

0 comments on commit fd2fc62

Please sign in to comment.