Skip to content

create_sampling_rule async

create_sampling_rule(
    sampling_rule: SamplingRule,
    *,
    config_overrides: Optional[AsyncXRayClientConfig] = None,
    tags: Optional[TagList] = None,
) -> CreateSamplingRuleResult

Creates a rule to control sampling behavior for instrumented applications. Services retrieve rules with GetSamplingRules, and evaluate each rule in ascending order of priority for each request. If a rule matches, the service records a trace, borrowing it from the reservoir size. After 10 seconds, the service reports back to X-Ray with GetSamplingTargets to get updated versions of each in-use rule. The updated rule contains a trace quota that the service can use instead of borrowing from the reservoir.

Parameters:

  • sampling_rule (SamplingRule) –

    The rule definition.

  • tags (Optional[TagList], default: None ) –

    A map that contains one or more tag keys and tag values to attach to an X-Ray sampling rule. For more information about ways to use tags, see Tagging Amazon Web Services resources in the Amazon Web Services General Reference.

    The following restrictions apply to tags:

    • Maximum number of user-applied tags per resource: 50

    • Maximum tag key length: 128 Unicode characters

    • Maximum tag value length: 256 Unicode characters

    • Valid values for key and value: a-z, A-Z, 0-9, space, and the following characters: _ . : / = + - and @

    • Tag keys and values are case sensitive.

    • Don't use aws: as a prefix for keys; it's reserved for Amazon Web Services use.

Raises:

Source code in docs_src/capo_xray/_services/async_x_ray.py
async def create_sampling_rule(
    self,
    sampling_rule: "capo_xray.types.sampling_rule.SamplingRule",
    *,
    config_overrides: Optional[AsyncXRayClientConfig] = None,
    tags: Optional["capo_xray.types.tag_list.TagList"] = None,
) -> "capo_xray.types.create_sampling_rule_result.CreateSamplingRuleResult":
    """<p>Creates a rule to control sampling behavior for instrumented applications. Services retrieve rules with <a href="https://docs.aws.amazon.com/xray/latest/api/API_GetSamplingRules.html">GetSamplingRules</a>, and evaluate each rule in ascending order of <i>priority</i> for each request. If a rule matches, the service records a trace, borrowing it from the reservoir size. After 10 seconds, the service reports back to X-Ray with <a href="https://docs.aws.amazon.com/xray/latest/api/API_GetSamplingTargets.html">GetSamplingTargets</a> to get updated versions of each in-use rule. The updated rule contains a trace quota that the service can use instead of borrowing from the reservoir.</p>

    Args:
        sampling_rule: <p>The rule definition.</p>
        tags: <p>A map that contains one or more tag keys and tag values to attach to an X-Ray sampling rule. For more information about ways to use tags, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html">Tagging Amazon Web Services resources</a> in the <i>Amazon Web Services General Reference</i>.</p> <p>The following restrictions apply to tags:</p> <ul> <li> <p>Maximum number of user-applied tags per resource: 50</p> </li> <li> <p>Maximum tag key length: 128 Unicode characters</p> </li> <li> <p>Maximum tag value length: 256 Unicode characters</p> </li> <li> <p>Valid values for key and value: a-z, A-Z, 0-9, space, and the following characters: _ . : / = + - and @</p> </li> <li> <p>Tag keys and values are case sensitive.</p> </li> <li> <p>Don't use <code>aws:</code> as a prefix for keys; it's reserved for Amazon Web Services use.</p> </li> </ul>

    Raises:
        capo_xray.errors.invalid_request_exception.InvalidRequestException: <p>The request is missing required parameters or has invalid parameters.</p>
        capo_xray.errors.rule_limit_exceeded_exception.RuleLimitExceededException: <p>You have reached the maximum number of sampling rules.</p>
        capo_xray.errors.throttled_exception.ThrottledException: <p>The request exceeds the maximum number of requests per second.</p>
        capo_xray.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_xray.types.create_sampling_rule_request.CreateSamplingRuleRequest]",
    ) -> AsyncOperationResponse[
        "capo_xray.types.create_sampling_rule_result.CreateSamplingRuleResult"
    ]:
        import capo_xray._operations.awsx_ray.create_sampling_rule

        (
            output,
            http_response,
        ) = await capo_xray._operations.awsx_ray.create_sampling_rule.async_create_sampling_rule(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateSamplingRule")
    )
    input_: capo_xray.types.create_sampling_rule_request.CreateSamplingRuleRequest = {
        "sampling_rule": sampling_rule
    }
    if tags is not None:
        input_["tags"] = tags

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output