Skip to content

Commit

Permalink
Add request attributes to tile trace logs
Browse files Browse the repository at this point in the history
Use mosaic reader requests to add custom dimensions to trace log output
  • Loading branch information
mmcfarland committed Jun 20, 2022
1 parent 05f3830 commit f461009
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pctiler/pctiler/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import attr
import morecantile
from pccommon.logging import get_custom_dimensions
import planetary_computer as pc
from cogeo_mosaic.errors import NoAssetFoundError
from fastapi import HTTPException
Expand Down Expand Up @@ -134,17 +135,17 @@ def assets_for_tile(
bbox = self.tms.bounds(morecantile.Tile(x, y, z))
assets = self.get_assets(Polygon.from_bounds(*bbox), **asset_kwargs)

te = time.perf_counter()
logger.info(
"Perf: Mosaic get assets for tile.",
extra={
"custom_dimensions": {
"duration": f"{te - ts:0.4f}",
extra=get_custom_dimensions(
{
"duration": f"{time.perf_counter() - ts:0.4f}",
"collection": collection,
"zxy": f"{z}/{x}/{y}",
"count": len(assets),
},
},
self.reader.request,

This comment has been minimized.

Copy link
@mmcfarland

mmcfarland Jun 20, 2022

Author Member

This results in AttributeError: type object 'MosaicSTACReader' has no attribute 'request'

This comment has been minimized.

Copy link
@vincentsarago

vincentsarago Jun 20, 2022

Contributor

I see, the problem here is that we don't initialize the reader (like we do here https://github.com/stac-utils/titiler-pgstac/blob/master/titiler/pgstac/mosaic.py#L364-L366)

But on the asset_for_tile endpoint (https://github.com/stac-utils/titiler-pgstac/blob/master/titiler/pgstac/factory.py#L296-L322) you could use quite a Hack by accessing self.reader_options["request"].

The main issue here is that you want to have access to request at Backend Level (not at reader level as introduced in this PR). Hopefully I can update the backend to make this possible.

),
)
return assets

Expand Down

0 comments on commit f461009

Please sign in to comment.