Skip to content

Commit e1d2a27

Browse files
committed
remove incomplete inputs from span attributes, add logging
1 parent cb85b10 commit e1d2a27

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

src/titiler/core/titiler/core/factory.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,11 @@ def tile(
873873
):
874874
"""Create map tile from a dataset."""
875875
tms = self.supported_tms.get(tileMatrixSetId)
876-
logger.info("opening dataset")
877876
with rasterio.Env(**env):
877+
logger.info(f"opening data with reader: {self.reader}")
878878
with self.reader(
879879
src_path, tms=tms, **reader_params.as_dict()
880880
) as src_dst:
881-
logger.info("reading data")
882881
image = src_dst.tile(
883882
x,
884883
y,
@@ -888,10 +887,10 @@ def tile(
888887
**layer_params.as_dict(),
889888
**dataset_params.as_dict(),
890889
)
891-
logger.info("reading data complete")
892890
dst_colormap = getattr(src_dst, "colormap", None)
893891

894892
if post_process:
893+
logger.info("post-processing image")
895894
image = post_process(image)
896895

897896
content, media_type = self.render_func(
@@ -980,6 +979,7 @@ def tilejson(
980979

981980
tms = self.supported_tms.get(tileMatrixSetId)
982981
with rasterio.Env(**env):
982+
logger.info(f"opening data with reader: {self.reader}")
983983
with self.reader(
984984
src_path, tms=tms, **reader_params.as_dict()
985985
) as src_dst:
@@ -1140,6 +1140,7 @@ def wmts(
11401140

11411141
tms = self.supported_tms.get(tileMatrixSetId)
11421142
with rasterio.Env(**env):
1143+
logger.info(f"opening data with reader: {self.reader}")
11431144
with self.reader(
11441145
src_path, tms=tms, **reader_params.as_dict()
11451146
) as src_dst:
@@ -1227,6 +1228,7 @@ def point(
12271228
):
12281229
"""Get Point value for a dataset."""
12291230
with rasterio.Env(**env):
1231+
logger.info(f"opening data with reader: {self.reader}")
12301232
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
12311233
pts = src_dst.point(
12321234
lon,
@@ -1283,6 +1285,7 @@ def preview(
12831285
):
12841286
"""Create preview of a dataset."""
12851287
with rasterio.Env(**env):
1288+
logger.info(f"opening data with reader: {self.reader}")
12861289
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
12871290
image = src_dst.preview(
12881291
**layer_params.as_dict(),
@@ -1346,6 +1349,7 @@ def bbox_image(
13461349
):
13471350
"""Create image from a bbox."""
13481351
with rasterio.Env(**env):
1352+
logger.info(f"opening data with reader: {self.reader}")
13491353
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
13501354
image = src_dst.part(
13511355
[minx, miny, maxx, maxy],
@@ -1407,6 +1411,7 @@ def feature_image(
14071411
):
14081412
"""Create image from a geojson feature."""
14091413
with rasterio.Env(**env):
1414+
logger.info(f"opening data with reader: {self.reader}")
14101415
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
14111416
image = src_dst.feature(
14121417
geojson.model_dump(exclude_none=True),
@@ -1478,6 +1483,7 @@ def info(
14781483
):
14791484
"""Return dataset's basic info or the list of available assets."""
14801485
with rasterio.Env(**env):
1486+
logger.info(f"opening data with reader: {self.reader}")
14811487
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
14821488
return src_dst.info(**asset_params.as_dict())
14831489

@@ -1503,6 +1509,7 @@ def info_geojson(
15031509
):
15041510
"""Return dataset's basic info as a GeoJSON feature."""
15051511
with rasterio.Env(**env):
1512+
logger.info(f"opening data with reader: {self.reader}")
15061513
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
15071514
bounds = src_dst.get_geographic_bounds(crs or WGS84_CRS)
15081515
geometry = bounds_to_geometry(bounds)
@@ -1527,6 +1534,7 @@ def available_assets(
15271534
):
15281535
"""Return a list of supported assets."""
15291536
with rasterio.Env(**env):
1537+
logger.info(f"opening data with reader: {self.reader}")
15301538
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
15311539
return src_dst.assets
15321540

@@ -1560,6 +1568,7 @@ def asset_statistics(
15601568
):
15611569
"""Per Asset statistics"""
15621570
with rasterio.Env(**env):
1571+
logger.info(f"opening data with reader: {self.reader}")
15631572
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
15641573
return src_dst.statistics(
15651574
**asset_params.as_dict(),
@@ -1597,6 +1606,7 @@ def statistics(
15971606
):
15981607
"""Merged assets statistics."""
15991608
with rasterio.Env(**env):
1609+
logger.info(f"opening data with reader: {self.reader}")
16001610
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
16011611
# Default to all available assets
16021612
if not layer_params.assets and not layer_params.expression:
@@ -1653,6 +1663,7 @@ def geojson_statistics(
16531663
fc = FeatureCollection(type="FeatureCollection", features=[geojson])
16541664

16551665
with rasterio.Env(**env):
1666+
logger.info(f"opening data with reader: {self.reader}")
16561667
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
16571668
# Default to all available assets
16581669
if not layer_params.assets and not layer_params.expression:
@@ -1729,6 +1740,7 @@ def info(
17291740
):
17301741
"""Return dataset's basic info."""
17311742
with rasterio.Env(**env):
1743+
logger.info(f"opening data with reader: {self.reader}")
17321744
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
17331745
return src_dst.info(**bands_params.as_dict())
17341746

@@ -1754,6 +1766,7 @@ def info_geojson(
17541766
):
17551767
"""Return dataset's basic info as a GeoJSON feature."""
17561768
with rasterio.Env(**env):
1769+
logger.info(f"opening data with reader: {self.reader}")
17571770
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
17581771
bounds = src_dst.get_geographic_bounds(crs or WGS84_CRS)
17591772
geometry = bounds_to_geometry(bounds)
@@ -1778,6 +1791,7 @@ def available_bands(
17781791
):
17791792
"""Return a list of supported bands."""
17801793
with rasterio.Env(**env):
1794+
logger.info(f"opening data with reader: {self.reader}")
17811795
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
17821796
return src_dst.bands
17831797

@@ -1811,6 +1825,7 @@ def statistics(
18111825
):
18121826
"""Get Dataset statistics."""
18131827
with rasterio.Env(**env):
1828+
logger.info(f"opening data with reader: {self.reader}")
18141829
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
18151830
# Default to all available bands
18161831
if not bands_params.bands and not bands_params.expression:
@@ -1867,6 +1882,7 @@ def geojson_statistics(
18671882
fc = FeatureCollection(type="FeatureCollection", features=[geojson])
18681883

18691884
with rasterio.Env(**env):
1885+
logger.info(f"opening data with reader: {self.reader}")
18701886
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
18711887
# Default to all available bands
18721888
if not bands_params.bands and not bands_params.expression:

src/titiler/core/titiler/core/telemetry.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,6 @@ def _get_span_name(op_name: str, factory_instance: Any) -> str:
9696
return f"{class_name}.{op_name}"
9797

9898

99-
def _extract_span_attributes(
100-
sig: inspect.Signature, *args: Any, **kwargs: Any
101-
) -> Dict[str, Any]:
102-
"""Automatically extract primitive types from endpoint signature."""
103-
try:
104-
bound_args = sig.bind(*args, **kwargs)
105-
bound_args.apply_defaults()
106-
auto_attrs = {}
107-
for key, value in bound_args.arguments.items():
108-
if key in ("self", "request") or value is None:
109-
continue
110-
if hasattr(value, "value"):
111-
value = value.value
112-
if isinstance(value, (str, bool, int, float)):
113-
auto_attrs[f"titiler.path_param.{key}"] = value
114-
return auto_attrs
115-
except Exception:
116-
return {}
117-
118-
11999
def factory_trace(
120100
_func: Optional[Callable[P, Any]] = None,
121101
*,
@@ -128,15 +108,13 @@ def decorator(func: Callable[P, Any]) -> Callable[P, Any]:
128108
return func
129109

130110
op_name = func.__name__
131-
sig = inspect.signature(func)
132111

133112
if inspect.iscoroutinefunction(func):
134113

135114
@functools.wraps(func)
136115
async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
137116
span_name = _get_span_name(op_name, factory_instance)
138-
attributes = _extract_span_attributes(sig, *args, **kwargs)
139-
with operation_tracer(span_name, attributes=attributes):
117+
with operation_tracer(span_name):
140118
return await func(*args, **kwargs)
141119

142120
return async_wrapper
@@ -145,8 +123,7 @@ async def async_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
145123
@functools.wraps(func)
146124
def sync_wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
147125
span_name = _get_span_name(op_name, factory_instance)
148-
attributes = _extract_span_attributes(sig, *args, **kwargs)
149-
with operation_tracer(span_name, attributes=attributes):
126+
with operation_tracer(span_name):
150127
return func(*args, **kwargs)
151128

152129
return sync_wrapper

src/titiler/mosaic/titiler/mosaic/factory.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""TiTiler.mosaic Router factories."""
22

3+
import logging
34
import os
45
from typing import Any, Callable, Dict, List, Literal, Optional, Set, Tuple, Type, Union
56
from urllib.parse import urlencode
@@ -55,6 +56,8 @@
5556
"yes",
5657
]
5758

59+
logger = logging.getLogger(__name__)
60+
5861

5962
def PixelSelectionParams(
6063
pixel_selection: Annotated[ # type: ignore

src/titiler/xarray/titiler/xarray/factory.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""TiTiler.xarray factory."""
22

3+
import logging
34
from typing import Any, Callable, Optional, Type, Union
45

56
import rasterio
@@ -28,6 +29,8 @@
2829
from titiler.xarray.dependencies import DatasetParams, PartFeatureParams, XarrayParams
2930
from titiler.xarray.io import Reader
3031

32+
logger = logging.getLogger(__name__)
33+
3134

3235
@define(kw_only=True)
3336
class TilerFactory(BaseTilerFactory):
@@ -84,6 +87,7 @@ def info_endpoint(
8487
) -> Info:
8588
"""Return dataset's basic info."""
8689
with rasterio.Env(**env):
90+
logger.info(f"opening data with reader: {self.reader}")
8791
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
8892
info = src_dst.info().model_dump()
8993
if show_times and "time" in src_dst.input.dims:
@@ -118,6 +122,7 @@ def info_geojson(
118122
):
119123
"""Return dataset's basic info as a GeoJSON feature."""
120124
with rasterio.Env(**env):
125+
logger.info(f"opening data with reader: {self.reader}")
121126
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
122127
bounds = src_dst.get_geographic_bounds(crs or WGS84_CRS)
123128
geometry = bounds_to_geometry(bounds)
@@ -175,6 +180,7 @@ def geojson_statistics(
175180
fc = FeatureCollection(type="FeatureCollection", features=[geojson])
176181

177182
with rasterio.Env(**env):
183+
logger.info(f"opening data with reader: {self.reader}")
178184
with self.reader(src_path, **reader_params.as_dict()) as src_dst:
179185
for feature in fc.features:
180186
shape = feature.model_dump(exclude_none=True)

0 commit comments

Comments
 (0)