Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize Logs #3361

Open
3 of 4 tasks
jeremydvoss opened this issue Jun 27, 2023 · 11 comments
Open
3 of 4 tasks

Stabilize Logs #3361

jeremydvoss opened this issue Jun 27, 2023 · 11 comments

Comments

@jeremydvoss
Copy link
Contributor

jeremydvoss commented Jun 27, 2023

After confirming all of the following have been taken care of, I think we can stabilized logs. Got these from open-telemetry/opentelemetry-specification#2911

Is your feature request related to a problem?
Leaving Logs unstable enabled breaking changes like #2943

Describe the solution you'd like
With the logging spec stable, we should confirm we have everything we need and stabilize logs as soon as possible.

@jeremydvoss
Copy link
Contributor Author

Confirmed emit does not seem to default timestamp. This also means that trying to export that LogRecord to console fails because it cannot format timestamp. LogRecord.to_json() does not expect None. EX:

from opentelemetry.sdk.logs.export import ConsoleLogExporter, BatchLogRecordProcessor

lr = LogRecord()
print("timestamp: %s" % lr.timestamp)

# logger = Logger()
lp = LoggerProvider()
lp.add_log_record_processor(BatchLogRecordProcessor(ConsoleLogExporter()))
logger = lp.get_logger(__name__)

logger.emit(lr)

@jeremydvoss
Copy link
Contributor Author

Looking into include_trace_context, it does not seem python has this to begin with. LoggingHandler.emit calls LoggingHandler._translate which uses get_current_span().get_span_context(). This may be an optional feature for if we want people to be able to EXPLICATELY set the context of a logger.

Related question: should a log's trace context fields be populated if include_trace_context=false and context is explicitly passed? I think yes. However, for languages that rely on explicit context because no implicit context is available, there's no point to having the include_trace_context parameter since it doesn't change any behavior
https://github.com/open-telemetry/opentelemetry-specification/pull/3387/files

@jeremydvoss
Copy link
Contributor Author

Here is the observed_timestamp field

@jeremydvoss
Copy link
Contributor Author

jeremydvoss commented Jun 28, 2023

Seems we are NOT defaulting observed_timestamp to current time. We could change this in the sdk...

class LogRecord(APILogRecord):
    def __init__(
        ...
    ):
        if not observed_timestamp:
            observed_timestamp = int(time.time() * 1e9)
        super().__init__(
            ...

... or in the api:

class LogRecord(ABC):

    def __init__(
        ...
    ):
        self.timestamp = timestamp
        if observed_timestamp:
            self.observed_timestamp = observed_timestamp
        else:
            self.observed_timestamp = int(time.time() * 1e9)
        self.trace_id = trace_id
        ...

I am getting int(time.time() * 1e9) from how to translate native logs

@jeremydvoss
Copy link
Contributor Author

Use time.time_ns()

@jenshnielsen
Copy link
Contributor

Perhaps it would be worth including a fix for #3353 before stabilizing. This might not technically be a breaking change but it does significantly change the messages received

@lzchen
Copy link
Contributor

lzchen commented Jul 6, 2023

@jenshnielsen

I don't believe the issue exists within the SDK itself so it wouldn't be a blocker.

@lzchen
Copy link
Contributor

lzchen commented Sep 25, 2023

Might be another issue: #3193

@jeremydvoss
Copy link
Contributor Author

Take a look at #3608

@jeremydvoss
Copy link
Contributor Author

Take a look at #3810

@lzchen lzchen added the logging label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To do
Development

No branches or pull requests

3 participants