コード例 #1
0
 def configure_context(self, context: MetricsContext) -> None:
     if self.metadata is not None:
         context.set_property("imageId", self.metadata["imageId"])
         context.set_property("instanceId", self.metadata["instanceId"])
         context.set_property("instanceType", self.metadata["instanceType"])
         context.set_property("privateIp", self.metadata["privateIp"])
         context.set_property("availabilityZone",
                              self.metadata["availabilityZone"])
コード例 #2
0
def test_create_copy_with_context_does_not_copy_metrics():
    # arrange
    context = MetricsContext()
    prop_key = fake.word()
    prop_value = fake.word()
    context.set_property(prop_key, prop_value)

    # act
    new_context = context.create_copy_with_context()

    # assert
    assert len(new_context.metrics) == 0
コード例 #3
0
def test_create_copy_with_context_copies_properties():
    # arrange
    context = MetricsContext()
    prop_key = fake.word()
    prop_value = fake.word()
    context.set_property(prop_key, prop_value)

    # act
    new_context = context.create_copy_with_context()

    # assert
    assert context.properties == new_context.properties
    assert context.properties is not new_context.properties
コード例 #4
0
    def configure_context(self, context: MetricsContext) -> None:
        context.set_property("executionEnvironment",
                             get_env("AWS_EXECUTION_ENV"))
        context.set_property("memorySize",
                             get_env("AWS_LAMBDA_FUNCTION_MEMORY_SIZE"))
        context.set_property("functionVersion",
                             get_env("AWS_LAMBDA_FUNCTION_VERSION"))
        context.set_property("logStreamId",
                             get_env("AWS_LAMBDA_LOG_STREAM_NAME"))
        trace_id = get_env("_X_AMZN_TRACE_ID")

        if len(trace_id) > 0 and "Sampled=1" in trace_id:
            context.set_property("traceId", trace_id)