Exemple #1
0
def test_timer() -> None:
    time = TestingClock()

    t = Timer("timer", clock=time)
    time.sleep(10.0)
    t.mark("thing1")
    time.sleep(10.0)
    t.mark("thing2")
    assert t.finish() == {
        "timestamp": 0.0,
        "duration_ms": (10.0 + 10.0) * 1000,
        "marks_ms": {"thing1": 10.0 * 1000, "thing2": 10.0 * 1000},
        "tags": {},
    }
    assert t.get_duration_group() == ">20s"

    # Test that we can add more time under the same marks and the time will
    # be cumulatively added under those keys.
    time.sleep(10.0)
    t.mark("thing1")
    time.sleep(10.0)
    t.mark("thing2")
    assert t.finish() == {
        "timestamp": 0.0,
        "duration_ms": (10.0 + 10.0) * 2 * 1000,
        "marks_ms": {"thing1": 10.0 * 2 * 1000, "thing2": 10.0 * 2 * 1000},
        "tags": {},
    }
    assert t.get_duration_group() == ">30s"
Exemple #2
0
def _add_tags(timer: Timer, request: Optional[Request] = None) -> None:
    if Hub.current.scope.span:
        duration_group = timer.get_duration_group()
        sentry_sdk.set_tag("duration_group", duration_group)
        if duration_group == ">30s":
            sentry_sdk.set_tag("timeout", "too_long")

        if request is not None:
            experiments: MutableMapping[str,
                                        Any] = request.query.get_experiments()
            for name, value in experiments.items():
                sentry_sdk.set_tag(f"exp-{name}", str(value))
Exemple #3
0
def _add_tags(
    timer: Timer,
    experiments: Optional[Mapping[str, Any]] = None,
    metadata: Optional[SnubaQueryMetadata] = None,
) -> None:
    if Hub.current.scope.span:
        duration_group = timer.get_duration_group()
        sentry_sdk.set_tag("duration_group", duration_group)
        if duration_group == ">30s":
            sentry_sdk.set_tag("timeout", "too_long")
        if experiments is not None:
            for name, value in experiments.items():
                sentry_sdk.set_tag(name, str(value))
        if metadata is not None:
            for query_data in metadata.query_list:
                max_threads = query_data.stats.get("max_threads")
                if max_threads is not None:
                    sentry_sdk.set_tag("max_threads", max_threads)
                    break