Skip to content

Commit 804bdd5

Browse files
committed
Add options to enable/disable sentry
1 parent 8a99c07 commit 804bdd5

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

pinecone/config.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323

2424

2525
def _set_sentry_tags(config: dict):
26-
sentry_sdk.set_tag("package_version", CLIENT_VERSION)
27-
sentry_tag_names = ('environment', 'project_name', 'controller_host', 'username', 'user_label')
28-
for key, val in config.items():
29-
if key in sentry_tag_names:
30-
sentry_sdk.set_tag(key, val)
26+
if config['disable_error_reporting']:
27+
sentry_sdk.init()
28+
else:
29+
sentry_sdk.set_tag("package_version", CLIENT_VERSION)
30+
sentry_tag_names = ('environment', 'project_name', 'controller_host', 'username', 'user_label')
31+
for key, val in config.items():
32+
if key in sentry_tag_names:
33+
sentry_sdk.set_tag(key, val)
3134

3235

3336
class ConfigBase(NamedTuple):
@@ -36,6 +39,7 @@ class ConfigBase(NamedTuple):
3639
project_name: str = ""
3740
controller_host: str = ""
3841
log_level: str = ""
42+
disable_error_reporting: bool = False
3943
openapi_config: OpenApiConfiguration = None
4044

4145

@@ -134,6 +138,14 @@ def reset(self, config_file=None, **kwargs):
134138
self._config = config
135139

136140
# Sentry
141+
disable_error_reporting = (
142+
kwargs.pop("disable_error_reporting", False)
143+
or os.getenv("PINECONE_ERROR_REPORTING")
144+
or file_config.pop("disable_error_reporting", False)
145+
or False
146+
)
147+
config = config._replace(disable_error_reporting=disable_error_reporting)
148+
self._config = config
137149
_set_sentry_tags({**whoami_response._asdict(), **self._config._asdict()})
138150

139151
def _preprocess_and_validate_config(self, config: dict) -> dict:
@@ -191,10 +203,14 @@ def OPENAPI_CONFIG(self):
191203
def LOG_LEVEL(self):
192204
return self._config.log_level
193205

206+
@property
207+
def DISABLE_ERROR_REPORTING(self):
208+
return self._config.disable_error_reporting
209+
194210

195211
@sentry
196212
def init(api_key: str = None, host: str = None, environment: str = None, project_name: str = None,
197-
log_level: str = None, openapi_config: OpenApiConfiguration = None,
213+
log_level: str = None, openapi_config: OpenApiConfiguration = None, disable_error_reporting: bool = None,
198214
config: str = "~/.pinecone", **kwargs):
199215
"""Initializes the Pinecone client.
200216
@@ -203,11 +219,12 @@ def init(api_key: str = None, host: str = None, environment: str = None, project
203219
:param environment: Optional. Deployment environment.
204220
:param project_name: Optional. Pinecone project name. Overrides the value that is otherwise looked up and used from the Pinecone backend.
205221
:param log_level: Optional. Set Pinecone log level.
222+
:param disable_error_reporting: Optional. Don't sent client errors to Pinecone.
206223
:param openapi_config: Optional. Set OpenAPI client configuration.
207224
:param config: Optional. An INI configuration file.
208225
"""
209226
Config.reset(project_name=project_name, api_key=api_key, controller_host=host, environment=environment,
210-
log_level=log_level, openapi_config=openapi_config,
227+
log_level=log_level, openapi_config=openapi_config, disable_error_reporting=disable_error_reporting,
211228
config_file=config, **kwargs)
212229
if not bool(Config.API_KEY):
213230
logger.warning("API key is required.")

0 commit comments

Comments
 (0)