Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FDS-2386] Global client caching, Telemetry auto instruementation #1129

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
path: |
${{ steps.get-dependencies.outputs.site_packages_loc }}
${{ steps.get-dependencies.outputs.site_bin_dir }}
key: ${{ runner.os }}-${{ matrix.python }}-build-${{ env.cache-name }}-${{ hashFiles('setup.py') }}-v17
key: ${{ runner.os }}-${{ matrix.python }}-build-${{ env.cache-name }}-${{ hashFiles('setup.py') }}-v18

- name: Install py-dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
Expand Down
339 changes: 233 additions & 106 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ trace.set_tracer_provider(
)
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter()))
tracer = trace.get_tracer("my_tracer")
synapseclient.Synapse.enable_open_telemetry(True)

@tracer.start_as_current_span("my_span_name")
def main():
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ install_requires =
opentelemetry-api>=1.21.0
opentelemetry-sdk>=1.21.0
opentelemetry-exporter-otlp-proto-http>=1.21.0
opentelemetry-instrumentation-httpx>=0.48b0
opentelemetry-instrumentation-requests>=0.48b0
opentelemetry-instrumentation-threading>=0.48b0
opentelemetry-instrumentation-urllib>=0.48b0
nest-asyncio~=1.6.0
asyncio-atexit~=1.0.1
httpx~=0.27.0
Expand Down
10 changes: 6 additions & 4 deletions synapseclient/api/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def set_annotations(
Arguments:
annotations: The annotations to set. This is expected to have the id, etag,
and annotations filled in.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns: The annotations set in Synapse.
"""
Expand Down Expand Up @@ -58,8 +59,9 @@ async def set_annotations_async(
Arguments:
annotations: The annotations to set. This is expected to have the id, etag,
and annotations filled in.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns: The annotations set in Synapse.
"""
Expand Down
20 changes: 12 additions & 8 deletions synapseclient/api/entity_bundle_services_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ async def get_entity_id_bundle2(
- includeAnnotations: True
- includeFileHandles: True
- includeRestrictionInformation: True
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested entity bundle matching
Expand Down Expand Up @@ -69,8 +70,9 @@ async def get_entity_id_version_bundle2(
- includeAnnotations: True
- includeFileHandles: True
- includeRestrictionInformation: True
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested entity bundle matching
Expand Down Expand Up @@ -103,8 +105,9 @@ async def post_entity_bundle2_create(
request: The request for the bundle matching
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/entitybundle/v2/EntityBundleCreate.html>
generated_by: The ID of the activity to associate with the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested entity bundle matching
Expand Down Expand Up @@ -133,8 +136,9 @@ async def put_entity_id_bundle2(
request: The request for the bundle matching
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/entitybundle/v2/EntityBundleCreate.html>
generated_by: The ID of the activity to associate with the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested entity bundle matching
Expand Down
20 changes: 13 additions & 7 deletions synapseclient/api/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ async def get_from_entity_factory(
hop to the target of the link.
entity_to_update: An existing entity class instance to update with data from
Synapse.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Example: Using this function
Download file into cache
Expand Down Expand Up @@ -127,7 +128,10 @@ async def get_from_entity_factory(

# Check and warn for unmet access requirements
_check_entity_restrictions(
bundle=bundle, synapse_id=bundle["entity"]["id"], download_file=download_file
bundle=bundle,
synapse_id=bundle["entity"]["id"],
download_file=download_file,
synapse_client=synapse_client,
)

return_data = await _cast_into_class_type(
Expand Down Expand Up @@ -166,8 +170,9 @@ async def _search_for_file_by_md5(
md5: The MD5 of the file to retrieve. If not passed in, the MD5 will be
calculated.
limit_search: Limit the search to a specific project or folder.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
A dictionary containing the entity bundle of the file found.
Expand Down Expand Up @@ -255,8 +260,9 @@ class type. This will also download the file if `download_file` is set to True.
hop to the target of the link.
entity_to_update: An existing entity class instance to update with data from
Synapse.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
A Synapse entity object.
Expand Down
45 changes: 27 additions & 18 deletions synapseclient/api/entity_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ async def post_entity(
request: The request for the entity matching
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/Entity.html>
generated_by: The ID of the activity to associate with the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested entity matching
Expand Down Expand Up @@ -55,8 +56,9 @@ async def put_entity(
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/Entity.html>
new_version: If true, a new version of the entity will be created.
generated_by: The ID of the activity to associate with the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested entity bundle matching
Expand Down Expand Up @@ -84,8 +86,9 @@ async def get_entity(
"""
Arguments:
entity_id: The ID of the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested entity bundle matching
Expand Down Expand Up @@ -113,8 +116,9 @@ async def get_upload_destination(

Arguments:
entity_id: The ID of the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The upload destination.
Expand All @@ -138,8 +142,9 @@ async def get_upload_destination_location(
Arguments:
entity_id: The ID of the entity.
location: A storage location ID of the upload destination.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The upload destination.
Expand All @@ -162,8 +167,9 @@ async def create_access_requirements_if_none(

Arguments:
entity_id: The ID of the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.
"""
from synapseclient import Synapse

Expand Down Expand Up @@ -195,8 +201,9 @@ async def delete_entity_generated_by(
"""
Arguments:
entity_id: The ID of the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns: None
"""
Expand All @@ -219,8 +226,9 @@ async def get_entity_path(

Arguments:
entity_id: The ID of the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
Entity paths matching:
Expand All @@ -245,8 +253,9 @@ async def get_entities_by_md5(

Arguments:
md5: The MD5 of the entity.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
Paginated results of:
Expand Down
50 changes: 30 additions & 20 deletions synapseclient/api/file_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ async def post_file_multipart(
force_restart: Optional parameter. When True, any upload state for the given
file will be cleared and a new upload will be started.
endpoint: Server endpoint to call to.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The requested multipart upload status matching
Expand Down Expand Up @@ -87,8 +88,9 @@ async def put_file_multipart_add(
md5_hex: The MD5 of the uploaded part represented as a hexadecimal string. If
the provided MD5 does not match the MD5 of the uploaded part, the add
will fail.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
Object matching
Expand Down Expand Up @@ -126,8 +128,9 @@ async def put_file_multipart_complete(
Arguments:
upload_id: The unique identifier of the file upload.
endpoint: Server endpoint to call to.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
Object matching
Expand All @@ -154,8 +157,9 @@ async def post_file_multipart_presigned_urls(
Arguments:
upload_id: The unique identifier of the file upload.
part_numbers: The part numbers to get pre-signed URLs for.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
Object matching
Expand Down Expand Up @@ -199,8 +203,9 @@ async def post_external_object_store_filehandle(
storage_location_id: The optional storage location descriptor
mimetype: The Mimetype of the file, if known.
md5: The file's content MD5, if known.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
A FileHandle for objects that are stored externally.
Expand Down Expand Up @@ -243,8 +248,9 @@ async def post_external_filehandle(
mimetype: The Mimetype of the file, if known.
md5: The file's content MD5.
file_size: The size of the file in bytes.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
A FileHandle for objects that are stored externally.
Expand Down Expand Up @@ -299,8 +305,9 @@ async def post_external_s3_file_handle(
mutually exclusive with parent
mimetype: Mimetype of the file, if known
md5: MD5 of the file, if known
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
The created file handle.
Expand Down Expand Up @@ -360,8 +367,9 @@ async def get_file_handle(

Arguments:
file_handle_id: The ID of the file handle to look up.
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Returns:
A file handle retrieved from the file handle service.
Expand Down Expand Up @@ -392,8 +400,9 @@ async def get_file_handle_for_download_async(
entity_type: Type of object associated with a file e.g. FileEntity,
TableEntity
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/file/FileHandleAssociateType.html>
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Raises:
SynapseFileNotFoundError: If the fileHandleId is not found in Synapse.
Expand Down Expand Up @@ -452,8 +461,9 @@ def get_file_handle_for_download(
entity_type: Type of object associated with a file e.g. FileEntity,
TableEntity
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/file/FileHandleAssociateType.html>
synapse_client: If not passed in or None this will use the last client from
the `.login()` method.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
insance from the Synapse class constructor.

Raises:
SynapseFileNotFoundError: If the fileHandleId is not found in Synapse.
Expand Down
Loading
Loading