Skip to content

Send

provide.foundation.cli.commands.logs.send

TODO: Add module docstring.

Functions

send_command

send_command(
    ctx: Context,
    message: str | None,
    level: str,
    service_name: str | None,
    json_attrs: str | None,
    attr: tuple[str, ...],
    trace_id: str | None,
    span_id: str | None,
) -> int | None

Send a log entry to OpenObserve.

Examples:

Send a simple log

foundation logs send -m "User logged in" -l INFO

Send with attributes

foundation logs send -m "Payment processed" --attr user_id=123 --attr amount=99.99

Send from stdin

echo "Application started" | foundation logs send -l INFO

Send with JSON attributes

foundation logs send -m "Error occurred" -j '{"error_code": 500, "path": "/api/users"}'

Source code in provide/foundation/cli/commands/logs/send.py
@click.command("send")
@click.option(
    "--message",
    "-m",
    help="Log message to send (reads from stdin if not provided)",
)
@click.option(
    "--level",
    "-l",
    type=click.Choice(["TRACE", "DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"]),
    default="INFO",
    help="Log level",
)
@click.option(
    "--service",
    "-s",
    "service_name",
    help="Service name (uses config default if not provided)",
)
@click.option(
    "--json",
    "-j",
    "json_attrs",
    help="Additional attributes as JSON",
)
@click.option(
    "--attr",
    "-a",
    multiple=True,
    help="Additional attributes as key=value pairs",
)
@click.option(
    "--trace-id",
    help="Explicit trace ID to use",
)
@click.option(
    "--span-id",
    help="Explicit span ID to use",
)
@click.pass_context
@requires_click
@with_cleanup
def send_command(
    ctx: click.Context,
    message: str | None,
    level: str,
    service_name: str | None,
    json_attrs: str | None,
    attr: tuple[str, ...],
    trace_id: str | None,
    span_id: str | None,
) -> int | None:
    """Send a log entry to OpenObserve.

    Examples:
        # Send a simple log
        foundation logs send -m "User logged in" -l INFO

        # Send with attributes
        foundation logs send -m "Payment processed" --attr user_id=123 --attr amount=99.99

        # Send from stdin
        echo "Application started" | foundation logs send -l INFO

        # Send with JSON attributes
        foundation logs send -m "Error occurred" -j '{"error_code": 500, "path": "/api/users"}'

    """
    # Get message from input
    final_message, error_code = _get_message_from_input(message)
    if error_code != 0:
        exit_error("No message provided", code=error_code)

    # Build attributes using shared helper
    attributes, error_code = build_attributes_from_args(json_attrs, attr)
    if error_code != 0:
        exit_error("Invalid attributes", code=error_code)

    # Send the log entry
    result = _send_log_entry(
        final_message,  # type: ignore[arg-type]
        level,
        service_name,
        attributes,
        trace_id,
        span_id,
    )

    if result == 0:
        exit_success()
    else:
        exit_error("Failed to send log", code=result)

    return None