|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +"""Attribution module for tracking the provenance of SDK usage.""" |
| 14 | +from __future__ import absolute_import |
| 15 | +import os |
| 16 | +from enum import Enum |
| 17 | + |
| 18 | +_CREATED_BY_ENV_VAR = "SAGEMAKER_PYSDK_CREATED_BY" |
| 19 | + |
| 20 | + |
| 21 | +class Attribution(Enum): |
| 22 | + """Enumeration of known SDK attribution sources.""" |
| 23 | + |
| 24 | + SAGEMAKER_AGENT_PLUGIN = "awslabs/agent-plugins/sagemaker-ai" |
| 25 | + |
| 26 | + |
| 27 | +def set_attribution(attribution: Attribution): |
| 28 | + """Sets the SDK usage attribution to the specified source. |
| 29 | +
|
| 30 | + Call this at the top of scripts generated by an agent or integration |
| 31 | + to enable accurate telemetry attribution. |
| 32 | +
|
| 33 | + Args: |
| 34 | + attribution (Attribution): The attribution source to set. |
| 35 | +
|
| 36 | + Raises: |
| 37 | + TypeError: If attribution is not an Attribution enum member. |
| 38 | + """ |
| 39 | + if not isinstance(attribution, Attribution): |
| 40 | + raise TypeError(f"attribution must be an Attribution enum member, got {type(attribution)}") |
| 41 | + os.environ[_CREATED_BY_ENV_VAR] = attribution.value |
0 commit comments