Hi Everyone, I am sending the metric in signoz usi...
# support
n
Hi Everyone, I am sending the metric in signoz using lambda
Copy code
def base_lambda_handler(event, context):
        counter = meter.create_counter(
            name="sachin_test",
            description="A counter metric for SigNoz",
        )

        # Record a Value
        counter.add(1, {"environment": "production"})
        counter.add(200, {"environment": "production"})
        counter.add(100, {"environment": "production"})
        histogram = meter.create_histogram(
            name="Nitish-metric-histogram",
            description="A histogram metric for value distribution",
        )

        # Record values
        histogram.record(1, {"environment": "production"})
        histogram.record(200, {"environment": "production"})
        histogram.record(100, {"environment": "production"})

    except Exception as e:
        logger.error(f"Error processing SQS event: {str(e)}")
        raise  # Raise to ensure this record is retried and can go to DLQ
    finally:
        # Flush the traces before the lambda function exits
        current_span.end()
        flush_traces()
        time.sleep(5)
tracing.py
Copy code
import os
from opentelemetry import trace, metrics
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
from opentelemetry.propagate import set_global_textmap
from opentelemetry.propagators.aws import AwsXRayPropagator
from common.logger import get_json_logger

# Initialize logger
logger = get_json_logger("Otel Tracing and Metrics")

# Global variables for tracer and meter
tracer = None
meter = None


def setup_opentelemetry_traces(service_name):
    logger.info(f"Starting OpenTelemetry configuration for service: {service_name}")
    global tracer

    # Set up AWS X-Ray Propagator for trace propagation (only need to set this once)
    set_global_textmap(AwsXRayPropagator())

    # Set resource attributes (service name and environment)
    resource_attributes = {"service.name": service_name}
    if os.environ.get("OTEL_RESOURCE_ATTRIBUTES"):
        resource_attributes = None  # Use resource attributes from environment variables
    resource = Resource.create(attributes=resource_attributes)

    # Configure tracing with OTLP exporter
    otlp_span_exporter = OTLPSpanExporter(
        endpoint=os.getenv("OTEL_ENDPOINT"),
        insecure=True,
        headers={"x-honeycomb-team": os.getenv("HONEYCOMB_API_KEY", "")},
    )
    tracer = TracerProvider(
        resource=resource,
        active_span_processor=BatchSpanProcessor(otlp_span_exporter),
        id_generator=RandomIdGenerator(),
    )
    trace.set_tracer_provider(tracer)
    logger.info("Tracer provider and span processor configured successfully.")

    # Configure metrics with OTLP exporter
    otlp_metric_exporter = OTLPMetricExporter(
        endpoint=os.getenv("OTEL_ENDPOINT"),
        insecure=True,
        headers={"x-honeycomb-team": os.getenv("HONEYCOMB_API_KEY", "")},
    )
    global meter
    metric_reader = PeriodicExportingMetricReader(otlp_metric_exporter)
    meter = MeterProvider(metric_readers=[metric_reader])
    metrics.set_meter_provider(meter)
    logger.info("Meter provider and metric exporter configured successfully.")


def flush_traces():
    """Flush any buffered traces immediately."""
    if tracer:
        tracer.force_flush()
    if meter:
        meter.force_flush()
But in signoz dashboard, I am only able to see the metric Name, not the data points
msg: "No DATA"
ScreenShot for ref: while traces are working as expected
h
we have work around where we are using updown metrics instead of counter metrics this is happening for standalone but when we checking the data point, this query is not returning proper data
Copy code
SELECT ts, sum(per_series_value) as value FROM (SELECT  ts, If((per_series_value - lagInFrame(per_series_value, 1, 0) OVER rate_window) < 0, nan, If((ts - lagInFrame(ts, 1, toDate('1970-01-01')) OVER rate_window) >= 86400, nan, (per_series_value - lagInFrame(per_series_value, 1, 0) OVER rate_window) / (ts - lagInFrame(ts, 1, toDate('1970-01-01')) OVER rate_window))) as per_series_value FROM (SELECT fingerprint,  toStartOfInterval(toDateTime(intDiv(unix_milli, 1000)), INTERVAL 60 SECOND) as ts, max(value) as per_series_value FROM signoz_metrics.distributed_samples_v4 INNER JOIN (SELECT DISTINCT fingerprint FROM signoz_metrics.time_series_v4_6hrs WHERE metric_name = 'example_counter' AND temporality = 'Cumulative' AND unix_milli >= 1736229600000 AND unix_milli < 1736254260000) as filtered_time_series USING fingerprint WHERE metric_name = 'example_counter' AND unix_milli >= 1736232600000 AND unix_milli < 1736254260000 GROUP BY fingerprint, ts ORDER BY fingerprint, ts) WINDOW rate_window as (PARTITION BY fingerprint ORDER BY fingerprint, ts)) WHERE isNaN(per_series_value) = 0 GROUP BY ts ORDER BY ts ASC
cc: @Chitransh Gupta
c
@Srikanth Chekuri could you please help out here.