1+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ # SPDX-License-Identifier: Apache-2.0
13import logging
24import re
35from typing import Dict , Optional
1416
1517_logger = logging .getLogger (__name__ )
1618
17-
1819class OTLPAwsSigV4Exporter (OTLPSpanExporter ):
1920
2021 def __init__ (
@@ -26,7 +27,7 @@ def __init__(
2627 headers : Optional [Dict [str , str ]] = None ,
2728 timeout : Optional [int ] = None ,
2829 compression : Optional [Compression ] = None ,
29- session : Optional [requests .Session ] = None ,
30+ rsession : Optional [requests .Session ] = None ,
3031 ):
3132
3233 self ._aws_region = self ._validate_exporter_endpoint (endpoint )
@@ -38,7 +39,7 @@ def __init__(
3839 headers = headers ,
3940 timeout = timeout ,
4041 compression = compression ,
41- session = session ,
42+ session = rsession ,
4243 )
4344
4445 def _export (self , serialized_data : bytes ):
@@ -59,7 +60,7 @@ def _export(self, serialized_data: bytes):
5960 signer .add_auth (request )
6061 self ._session .headers .update (dict (request .headers ))
6162
62- except Exception as signing_error :
63+ except ( BotoCoreError , ClientError , ValueError ) as signing_error :
6364 _logger .error (f"Failed to sign request: { signing_error } " )
6465
6566 else :
@@ -71,24 +72,24 @@ def _export(self, serialized_data: bytes):
7172 def _validate_exporter_endpoint (endpoint : str ) -> Optional [str ]:
7273 if not endpoint :
7374 return None
74-
75- match = re .search (rf" { AWS_SERVICE } \.([a-z0-9-]+)\.amazonaws\.com" , endpoint )
76-
75+
76+ match = re .search (f' { AWS_SERVICE } \.([a-z0-9-]+)\.amazonaws\.com' , endpoint )
77+
7778 if match :
7879 region = match .group (1 )
7980 xray_regions = session .Session ().get_available_regions (AWS_SERVICE )
80-
8181 if region in xray_regions :
8282 return region
83- _logger .error (f"Invalid AWS region: { region } . Valid regions are { xray_regions } ." )
84-
83+
84+ _logger .error ("Invalid AWS region: %s. Valid regions are %s. Resolving to default endpoint." ,
85+ region , xray_regions )
8586 return None
86-
87- _logger .error (
88- f"Invalid XRay traces endpoint: { endpoint } ."
89- "The traces endpoint follows the pattern https://xray.[AWSRegion].amazonaws.com/v1/traces. "
90- "For example, for the US West (Oregon) (us-west-2) Region, the endpoint will be "
91- "https://xray.us-west-2.amazonaws.com/v1/traces."
92- )
93-
87+
88+ _logger .error ("Invalid XRay traces endpoint: %s. Resolving to default endpoint. "
89+ "The traces endpoint follows the pattern https://xray.[AWSRegion].amazonaws.com/v1/traces. "
90+ "For example, for the US West (Oregon) (us-west-2) Region, the endpoint will be "
91+ "https://xray.us-west-2.amazonaws.com/v1/traces." ,
92+ endpoint )
93+
9494 return None
95+
0 commit comments