def METHOD_NAME():
    import time
    from ddtrace import tracer as t
    from tests.integration.test_priority_sampling import _prime_tracer_with_priority_sample_rate_from_agent
    from tests.integration.test_priority_sampling import _turn_tracer_into_dummy
    _id = time.time()
    env = "my-env-{}".format(_id)
    service = "my-svc-{}".format(_id)
    # send a ton of traces from different services to make the agent adjust its sample rate for ``service,env``
    for i in range(100):
        s = t.trace("operation", service="dummysvc{}".format(i))
        s.finish()
    t.flush()
    _prime_tracer_with_priority_sample_rate_from_agent(t, service, env)
    sampler_key = "service:{},env:{}".format(service, env)
    assert sampler_key in t._writer._sampler._by_service_samplers
    rate_from_agent = t._writer._sampler._by_service_samplers[sampler_key].sample_rate
    assert 0 < rate_from_agent < 1
    _turn_tracer_into_dummy(t)
    captured_span_count = 100
    for _ in range(captured_span_count):
        with t.trace("operation", service=service) as s:
            pass
        t.flush()
    assert len(t._writer.traces) == captured_span_count
    sampled_spans = [s for s in t._writer.spans if s.context._metrics[SAMPLING_PRIORITY_KEY] == AUTO_KEEP]
    sampled_ratio = len(sampled_spans) / captured_span_count
    diff_magnitude = abs(sampled_ratio - rate_from_agent)
    assert diff_magnitude < 0.3, "the proportion of sampled spans should approximate the sample rate given by the agent"
    t.shutdown()