Skip to content

logging: Public API for setting timestamp, severity, etc. on Entry #1348

Closed

Description

@zbjornson

I can't find a public API for setting the metadata fields like timestamp and severity on a log entry.

It works to do var entry = log.entry(...); entry.severity = "INFO";, which is similar to what's done internally in Log.assignSeverityToEntries_, but I think there should be an options object argument in the Entry constructor.

Activity

  1. stephenplusplus commented on Jun 1, 2016

    @stephenplusplus
    Contributor

    An Entry already takes two objects, the first for the resource details, the second for the data.

    We can change the resource argument to metadata:

    // before
    var entry = log.entry({
      type: 'gce_instance',
      labels: {
        zone: 'global',
        instance_id: '3'
      }
    }, {
      delegate: 'my_username'
    });
    
    entry.httpRequest = {...};
    
    // after
    var entry = log.entry({
      httpRequest: {...},
      resource: {
        type: 'gce_instance',
        labels: {
          zone: 'global',
          instance_id: '3'
        }
      }
    }, {
      delegate: 'my_username'
    });

    Which do you prefer?

    // @callmehiphop for thoughts

  2. callmehiphop commented on Jun 1, 2016

    @callmehiphop
    Contributor

    Could we just add an optional metadata field to the resource itself?

    var entry = log.entry({
      type: 'gce_instance',
      labels: {
        zone: 'global',
        instance_id: '3'
      },
      metadata: {
        httpRequest: {},
        timestamp: Date.now()
      }
    }, {
      delegate: 'my_username'
    });

    Or is that too weird?

  3. zbjornson commented on Jun 1, 2016

    @zbjornson
    ContributorAuthor

    Of the two, I think I like @stephenplusplus's proposal. The "resource" is already a bit confusing in nature, so it's nice to keep it explicitly separated. @stephenplusplus's is a breaking change though unless it's decided to keep supporting (resource, payload) in addition to the new ({resource, metadata}, payload).

  4. zbjornson commented on Jun 1, 2016

    @zbjornson
    ContributorAuthor

    I was also thinking (resource, options, payload), like

    entry(
      {type: type, labels: {}},
      {severity: severity},
      {message: "server up"}
    )
  5. stephenplusplus commented on Jun 1, 2016

    @stephenplusplus
    Contributor

    The only downside of the three arguments is that both resource* and options are optional, so if we only receive 2 arguments, we couldn't safely detect which kind it is. Breaking change is unfortunate, but not a deal breaker.

    *resource is optional because it can be specified at the time of the call to entry.write to apply to all of the entries given.

  6. zbjornson commented on Jun 1, 2016

    @zbjornson
    ContributorAuthor

    Good point! Then my vote stays with ({resource, metadata}, payload). :)

  7. added this to the milestone on Oct 3, 2016
  8. added a commit that references this issue on Feb 3, 2026
  9. added a commit that references this issue on Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: loggingIssues related to the Cloud Logging API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions