Skip to content

Commit 560c369

Browse files
authored
[FDS-2386] Global client caching, Telemetry auto instruementation (#1129)
* Add auto instrumentation, global client cache setting, and global telemetry setting
1 parent 70c8aac commit 560c369

File tree

72 files changed

+1991
-1632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1991
-1632
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
path: |
7878
${{ steps.get-dependencies.outputs.site_packages_loc }}
7979
${{ steps.get-dependencies.outputs.site_bin_dir }}
80-
key: ${{ runner.os }}-${{ matrix.python }}-build-${{ env.cache-name }}-${{ hashFiles('setup.py') }}-v17
80+
key: ${{ runner.os }}-${{ matrix.python }}-build-${{ env.cache-name }}-${{ hashFiles('setup.py') }}-v18
8181

8282
- name: Install py-dependencies
8383
if: steps.cache-dependencies.outputs.cache-hit != 'true'

Pipfile.lock

Lines changed: 233 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ trace.set_tracer_provider(
313313
)
314314
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
315315
tracer = trace.get_tracer("my_tracer")
316+
synapseclient.Synapse.enable_open_telemetry(True)
316317
317318
@tracer.start_as_current_span("my_span_name")
318319
def main():

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ install_requires =
5252
opentelemetry-api>=1.21.0
5353
opentelemetry-sdk>=1.21.0
5454
opentelemetry-exporter-otlp-proto-http>=1.21.0
55+
opentelemetry-instrumentation-httpx>=0.48b0
56+
opentelemetry-instrumentation-requests>=0.48b0
57+
opentelemetry-instrumentation-threading>=0.48b0
58+
opentelemetry-instrumentation-urllib>=0.48b0
5559
nest-asyncio~=1.6.0
5660
asyncio-atexit~=1.0.1
5761
httpx~=0.27.0

synapseclient/api/annotations.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def set_annotations(
2424
Arguments:
2525
annotations: The annotations to set. This is expected to have the id, etag,
2626
and annotations filled in.
27-
synapse_client: If not passed in or None this will use the last client from
28-
the `.login()` method.
27+
synapse_client: If not passed in and caching was not disabled by
28+
`Synapse.allow_client_caching(False)` this will use the last created
29+
insance from the Synapse class constructor.
2930
3031
Returns: The annotations set in Synapse.
3132
"""
@@ -58,8 +59,9 @@ async def set_annotations_async(
5859
Arguments:
5960
annotations: The annotations to set. This is expected to have the id, etag,
6061
and annotations filled in.
61-
synapse_client: If not passed in or None this will use the last client from
62-
the `.login()` method.
62+
synapse_client: If not passed in and caching was not disabled by
63+
`Synapse.allow_client_caching(False)` this will use the last created
64+
insance from the Synapse class constructor.
6365
6466
Returns: The annotations set in Synapse.
6567
"""

synapseclient/api/entity_bundle_services_v2.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ async def get_entity_id_bundle2(
2626
- includeAnnotations: True
2727
- includeFileHandles: True
2828
- includeRestrictionInformation: True
29-
synapse_client: If not passed in or None this will use the last client from
30-
the `.login()` method.
29+
synapse_client: If not passed in and caching was not disabled by
30+
`Synapse.allow_client_caching(False)` this will use the last created
31+
insance from the Synapse class constructor.
3132
3233
Returns:
3334
The requested entity bundle matching
@@ -69,8 +70,9 @@ async def get_entity_id_version_bundle2(
6970
- includeAnnotations: True
7071
- includeFileHandles: True
7172
- includeRestrictionInformation: True
72-
synapse_client: If not passed in or None this will use the last client from
73-
the `.login()` method.
73+
synapse_client: If not passed in and caching was not disabled by
74+
`Synapse.allow_client_caching(False)` this will use the last created
75+
insance from the Synapse class constructor.
7476
7577
Returns:
7678
The requested entity bundle matching
@@ -103,8 +105,9 @@ async def post_entity_bundle2_create(
103105
request: The request for the bundle matching
104106
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/entitybundle/v2/EntityBundleCreate.html>
105107
generated_by: The ID of the activity to associate with the entity.
106-
synapse_client: If not passed in or None this will use the last client from
107-
the `.login()` method.
108+
synapse_client: If not passed in and caching was not disabled by
109+
`Synapse.allow_client_caching(False)` this will use the last created
110+
insance from the Synapse class constructor.
108111
109112
Returns:
110113
The requested entity bundle matching
@@ -133,8 +136,9 @@ async def put_entity_id_bundle2(
133136
request: The request for the bundle matching
134137
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/entitybundle/v2/EntityBundleCreate.html>
135138
generated_by: The ID of the activity to associate with the entity.
136-
synapse_client: If not passed in or None this will use the last client from
137-
the `.login()` method.
139+
synapse_client: If not passed in and caching was not disabled by
140+
`Synapse.allow_client_caching(False)` this will use the last created
141+
insance from the Synapse class constructor.
138142
139143
Returns:
140144
The requested entity bundle matching

synapseclient/api/entity_factory.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ async def get_from_entity_factory(
5959
hop to the target of the link.
6060
entity_to_update: An existing entity class instance to update with data from
6161
Synapse.
62-
synapse_client: If not passed in or None this will use the last client from
63-
the `.login()` method.
62+
synapse_client: If not passed in and caching was not disabled by
63+
`Synapse.allow_client_caching(False)` this will use the last created
64+
insance from the Synapse class constructor.
6465
6566
Example: Using this function
6667
Download file into cache
@@ -127,7 +128,10 @@ async def get_from_entity_factory(
127128

128129
# Check and warn for unmet access requirements
129130
_check_entity_restrictions(
130-
bundle=bundle, synapse_id=bundle["entity"]["id"], download_file=download_file
131+
bundle=bundle,
132+
synapse_id=bundle["entity"]["id"],
133+
download_file=download_file,
134+
synapse_client=synapse_client,
131135
)
132136

133137
return_data = await _cast_into_class_type(
@@ -166,8 +170,9 @@ async def _search_for_file_by_md5(
166170
md5: The MD5 of the file to retrieve. If not passed in, the MD5 will be
167171
calculated.
168172
limit_search: Limit the search to a specific project or folder.
169-
synapse_client: If not passed in or None this will use the last client from
170-
the `.login()` method.
173+
synapse_client: If not passed in and caching was not disabled by
174+
`Synapse.allow_client_caching(False)` this will use the last created
175+
insance from the Synapse class constructor.
171176
172177
Returns:
173178
A dictionary containing the entity bundle of the file found.
@@ -255,8 +260,9 @@ class type. This will also download the file if `download_file` is set to True.
255260
hop to the target of the link.
256261
entity_to_update: An existing entity class instance to update with data from
257262
Synapse.
258-
synapse_client: If not passed in or None this will use the last client from
259-
the `.login()` method.
263+
synapse_client: If not passed in and caching was not disabled by
264+
`Synapse.allow_client_caching(False)` this will use the last created
265+
insance from the Synapse class constructor.
260266
261267
Returns:
262268
A Synapse entity object.

synapseclient/api/entity_services.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ async def post_entity(
2222
request: The request for the entity matching
2323
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/Entity.html>
2424
generated_by: The ID of the activity to associate with the entity.
25-
synapse_client: If not passed in or None this will use the last client from
26-
the `.login()` method.
25+
synapse_client: If not passed in and caching was not disabled by
26+
`Synapse.allow_client_caching(False)` this will use the last created
27+
insance from the Synapse class constructor.
2728
2829
Returns:
2930
The requested entity matching
@@ -55,8 +56,9 @@ async def put_entity(
5556
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/Entity.html>
5657
new_version: If true, a new version of the entity will be created.
5758
generated_by: The ID of the activity to associate with the entity.
58-
synapse_client: If not passed in or None this will use the last client from
59-
the `.login()` method.
59+
synapse_client: If not passed in and caching was not disabled by
60+
`Synapse.allow_client_caching(False)` this will use the last created
61+
insance from the Synapse class constructor.
6062
6163
Returns:
6264
The requested entity bundle matching
@@ -84,8 +86,9 @@ async def get_entity(
8486
"""
8587
Arguments:
8688
entity_id: The ID of the entity.
87-
synapse_client: If not passed in or None this will use the last client from
88-
the `.login()` method.
89+
synapse_client: If not passed in and caching was not disabled by
90+
`Synapse.allow_client_caching(False)` this will use the last created
91+
insance from the Synapse class constructor.
8992
9093
Returns:
9194
The requested entity bundle matching
@@ -113,8 +116,9 @@ async def get_upload_destination(
113116
114117
Arguments:
115118
entity_id: The ID of the entity.
116-
synapse_client: If not passed in or None this will use the last client from
117-
the `.login()` method.
119+
synapse_client: If not passed in and caching was not disabled by
120+
`Synapse.allow_client_caching(False)` this will use the last created
121+
insance from the Synapse class constructor.
118122
119123
Returns:
120124
The upload destination.
@@ -138,8 +142,9 @@ async def get_upload_destination_location(
138142
Arguments:
139143
entity_id: The ID of the entity.
140144
location: A storage location ID of the upload destination.
141-
synapse_client: If not passed in or None this will use the last client from
142-
the `.login()` method.
145+
synapse_client: If not passed in and caching was not disabled by
146+
`Synapse.allow_client_caching(False)` this will use the last created
147+
insance from the Synapse class constructor.
143148
144149
Returns:
145150
The upload destination.
@@ -162,8 +167,9 @@ async def create_access_requirements_if_none(
162167
163168
Arguments:
164169
entity_id: The ID of the entity.
165-
synapse_client: If not passed in or None this will use the last client from
166-
the `.login()` method.
170+
synapse_client: If not passed in and caching was not disabled by
171+
`Synapse.allow_client_caching(False)` this will use the last created
172+
insance from the Synapse class constructor.
167173
"""
168174
from synapseclient import Synapse
169175

@@ -195,8 +201,9 @@ async def delete_entity_generated_by(
195201
"""
196202
Arguments:
197203
entity_id: The ID of the entity.
198-
synapse_client: If not passed in or None this will use the last client from
199-
the `.login()` method.
204+
synapse_client: If not passed in and caching was not disabled by
205+
`Synapse.allow_client_caching(False)` this will use the last created
206+
insance from the Synapse class constructor.
200207
201208
Returns: None
202209
"""
@@ -219,8 +226,9 @@ async def get_entity_path(
219226
220227
Arguments:
221228
entity_id: The ID of the entity.
222-
synapse_client: If not passed in or None this will use the last client from
223-
the `.login()` method.
229+
synapse_client: If not passed in and caching was not disabled by
230+
`Synapse.allow_client_caching(False)` this will use the last created
231+
insance from the Synapse class constructor.
224232
225233
Returns:
226234
Entity paths matching:
@@ -245,8 +253,9 @@ async def get_entities_by_md5(
245253
246254
Arguments:
247255
md5: The MD5 of the entity.
248-
synapse_client: If not passed in or None this will use the last client from
249-
the `.login()` method.
256+
synapse_client: If not passed in and caching was not disabled by
257+
`Synapse.allow_client_caching(False)` this will use the last created
258+
insance from the Synapse class constructor.
250259
251260
Returns:
252261
Paginated results of:

synapseclient/api/file_services.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ async def post_file_multipart(
3636
force_restart: Optional parameter. When True, any upload state for the given
3737
file will be cleared and a new upload will be started.
3838
endpoint: Server endpoint to call to.
39-
synapse_client: If not passed in or None this will use the last client from
40-
the `.login()` method.
39+
synapse_client: If not passed in and caching was not disabled by
40+
`Synapse.allow_client_caching(False)` this will use the last created
41+
insance from the Synapse class constructor.
4142
4243
Returns:
4344
The requested multipart upload status matching
@@ -87,8 +88,9 @@ async def put_file_multipart_add(
8788
md5_hex: The MD5 of the uploaded part represented as a hexadecimal string. If
8889
the provided MD5 does not match the MD5 of the uploaded part, the add
8990
will fail.
90-
synapse_client: If not passed in or None this will use the last client from
91-
the `.login()` method.
91+
synapse_client: If not passed in and caching was not disabled by
92+
`Synapse.allow_client_caching(False)` this will use the last created
93+
insance from the Synapse class constructor.
9294
9395
Returns:
9496
Object matching
@@ -126,8 +128,9 @@ async def put_file_multipart_complete(
126128
Arguments:
127129
upload_id: The unique identifier of the file upload.
128130
endpoint: Server endpoint to call to.
129-
synapse_client: If not passed in or None this will use the last client from
130-
the `.login()` method.
131+
synapse_client: If not passed in and caching was not disabled by
132+
`Synapse.allow_client_caching(False)` this will use the last created
133+
insance from the Synapse class constructor.
131134
132135
Returns:
133136
Object matching
@@ -154,8 +157,9 @@ async def post_file_multipart_presigned_urls(
154157
Arguments:
155158
upload_id: The unique identifier of the file upload.
156159
part_numbers: The part numbers to get pre-signed URLs for.
157-
synapse_client: If not passed in or None this will use the last client from
158-
the `.login()` method.
160+
synapse_client: If not passed in and caching was not disabled by
161+
`Synapse.allow_client_caching(False)` this will use the last created
162+
insance from the Synapse class constructor.
159163
160164
Returns:
161165
Object matching
@@ -199,8 +203,9 @@ async def post_external_object_store_filehandle(
199203
storage_location_id: The optional storage location descriptor
200204
mimetype: The Mimetype of the file, if known.
201205
md5: The file's content MD5, if known.
202-
synapse_client: If not passed in or None this will use the last client from
203-
the `.login()` method.
206+
synapse_client: If not passed in and caching was not disabled by
207+
`Synapse.allow_client_caching(False)` this will use the last created
208+
insance from the Synapse class constructor.
204209
205210
Returns:
206211
A FileHandle for objects that are stored externally.
@@ -243,8 +248,9 @@ async def post_external_filehandle(
243248
mimetype: The Mimetype of the file, if known.
244249
md5: The file's content MD5.
245250
file_size: The size of the file in bytes.
246-
synapse_client: If not passed in or None this will use the last client from
247-
the `.login()` method.
251+
synapse_client: If not passed in and caching was not disabled by
252+
`Synapse.allow_client_caching(False)` this will use the last created
253+
insance from the Synapse class constructor.
248254
249255
Returns:
250256
A FileHandle for objects that are stored externally.
@@ -299,8 +305,9 @@ async def post_external_s3_file_handle(
299305
mutually exclusive with parent
300306
mimetype: Mimetype of the file, if known
301307
md5: MD5 of the file, if known
302-
synapse_client: If not passed in or None this will use the last client from
303-
the `.login()` method.
308+
synapse_client: If not passed in and caching was not disabled by
309+
`Synapse.allow_client_caching(False)` this will use the last created
310+
insance from the Synapse class constructor.
304311
305312
Returns:
306313
The created file handle.
@@ -360,8 +367,9 @@ async def get_file_handle(
360367
361368
Arguments:
362369
file_handle_id: The ID of the file handle to look up.
363-
synapse_client: If not passed in or None this will use the last client from
364-
the `.login()` method.
370+
synapse_client: If not passed in and caching was not disabled by
371+
`Synapse.allow_client_caching(False)` this will use the last created
372+
insance from the Synapse class constructor.
365373
366374
Returns:
367375
A file handle retrieved from the file handle service.
@@ -392,8 +400,9 @@ async def get_file_handle_for_download_async(
392400
entity_type: Type of object associated with a file e.g. FileEntity,
393401
TableEntity
394402
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/file/FileHandleAssociateType.html>
395-
synapse_client: If not passed in or None this will use the last client from
396-
the `.login()` method.
403+
synapse_client: If not passed in and caching was not disabled by
404+
`Synapse.allow_client_caching(False)` this will use the last created
405+
insance from the Synapse class constructor.
397406
398407
Raises:
399408
SynapseFileNotFoundError: If the fileHandleId is not found in Synapse.
@@ -452,8 +461,9 @@ def get_file_handle_for_download(
452461
entity_type: Type of object associated with a file e.g. FileEntity,
453462
TableEntity
454463
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/file/FileHandleAssociateType.html>
455-
synapse_client: If not passed in or None this will use the last client from
456-
the `.login()` method.
464+
synapse_client: If not passed in and caching was not disabled by
465+
`Synapse.allow_client_caching(False)` this will use the last created
466+
insance from the Synapse class constructor.
457467
458468
Raises:
459469
SynapseFileNotFoundError: If the fileHandleId is not found in Synapse.

0 commit comments

Comments
 (0)