-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from NASA-IMPACT/fix/workflow-imaghe-pull
feat(otel): Add otel, update image on push
- Loading branch information
Showing
4 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ xarray==2023.1.0 | |
xstac==1.1.0 | ||
zarr==2.13.6 | ||
boto3==1.24.59 | ||
aws_xray_sdk>=2.6.0,<3 | ||
aws-lambda-powertools>=1.18.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Observability utils""" | ||
from typing import Callable | ||
|
||
from aws_lambda_powertools import Logger, Metrics, Tracer | ||
from aws_lambda_powertools.metrics import MetricUnit # noqa: F401 | ||
|
||
from fastapi import Request, Response | ||
from fastapi.routing import APIRoute | ||
|
||
logger: Logger = Logger(service="raster-api", namespace="veda-backend") | ||
metrics: Metrics = Metrics(service="raster-api", namespace="veda-backend") | ||
tracer: Tracer = Tracer() | ||
|
||
|
||
class LoggerRouteHandler(APIRoute): | ||
"""Extension of base APIRoute to add context to log statements, as well as record usage metricss""" | ||
|
||
def get_route_handler(self) -> Callable: | ||
"""Overide route handler method to add logs, metrics, tracing""" | ||
original_route_handler = super().get_route_handler() | ||
|
||
async def route_handler(request: Request) -> Response: | ||
# Add fastapi context to logs | ||
ctx = { | ||
"path": request.url.path, | ||
"route": self.path, | ||
"method": request.method, | ||
} | ||
logger.append_keys(fastapi=ctx) | ||
logger.info("Received request") | ||
metrics.add_metric( | ||
name="/".join( | ||
str(request.url.path).split("/")[:2] | ||
), # enough detail to capture search IDs, but not individual tile coords | ||
unit=MetricUnit.Count, | ||
value=1, | ||
) | ||
tracer.put_annotation(key="path", value=request.url.path) | ||
tracer.capture_method(original_route_handler)(request) | ||
return await original_route_handler(request) | ||
|
||
return route_handler |