GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — logging: Serialization of Native Types · Issue #1352 · googleapis/google-cloud-node

logging: Serialization of Native Types #1352

New issue
Copy link
New issue
Copy link
Closed
Closed
logging: Serialization of Native Types#1352
Copy link
Assignees
yoshi-automation
Labels
api: loggingIssues related to the Cloud Logging API.

Description

@zbjornson
zbjornson
opened on Jun 1, 2016
Issue body actions

One more logging question/possible bug...

Built-in JS objects including Date, Error, undefined, and RegExp are not serializable into the proto. Is the intent to support these? (Maybe depends if you consider these "objects" when reading the JSON spec.)

var entry = log.entry(resource, {
  someDate: new Date()
});
log.write(entry...) // Error: .google.protobuf.Value#timestampValue is not a field: undefined
var entry = log.entry(resource, {
  someErr: new Error("ohno")
});
log.write(entry...) // Error: Value of type object not recognized
// same error for RegExp
var entry = log.entry(resource, {
  someValue: undefined
});
log.write(entry...) // Error: Value of type undefined not recognized

At least Date and Error are common in logs and I think nice to support (otherwise as a consumer I'm manually casting these to strings). The others (RegExp, typed arrays, others?) I think are less common. For comparison, BSON allows Date.

Activity

Next
  1. stephenplusplus commented on Jun 2, 2016

    @stephenplusplus
    stephenplusplus
    on Jun 2, 2016
    Contributor
    More actions

    The entry payload (the data object) is a Struct, defined here:

    message Value {
      oneof kind {
        NullValue null_value = 1;
        double number_value = 2;
        string string_value = 3;
        bool bool_value = 4;
        Struct struct_value = 5;
        ListValue list_value = 6;
      }
    }

    So just these types are supported, evidently. Is there anything we can do to make it easier to work with Date and Error values?

  2. stephenplusplus
    added
    api: loggingIssues related to the Cloud Logging API.
    on Jun 2, 2016
  3. stephenplusplus
    changed the title [-]logging: Serialization of Date, Error[/-] [+]logging: Serialization of Native Types[/+] on Jun 2, 2016
  4. zbjornson commented on Jun 2, 2016

    @zbjornson
    zbjornson
    on Jun 2, 2016
    ContributorAuthor
    More actions

    Assuming I'm correct in thinking that this interface is intended to consume JSONs and transparently use protos on the backend, then one approach could be to add something like this somewhere in Entry, to delete undefined values and coerce native types. (One key difference from above would be mapping Date to proto's Timestamp type.)

    Perhaps this should be up to the consumer, but I imagine many people will run into it.

  5. stephenplusplus commented on Jun 2, 2016

    @stephenplusplus
    stephenplusplus
    on Jun 2, 2016
    Contributor
    More actions

    @filipjs any thoughts about what we should do when a user of this library attempts to write one of these types-- RegExp, Date, Error, undefined-- in a log entry?

  6. filipjs commented on Jun 8, 2016

    @filipjs
    filipjs
    on Jun 8, 2016
    More actions

    Yes, we are only supporting JSON specification (so no date type unfortunately). Changing other objects to their string representation should work, like in the linked code sample.

  7. zbjornson commented on Jun 8, 2016

    @zbjornson
    zbjornson
    on Jun 8, 2016
    ContributorAuthor
    More actions

    That's reasonable. Date type is the only one I'm actually sad not to have, but when #1348 gets resolved then at least the entry timestamp will be settable and searchable.

  8. callmehiphop
    closed this as completedin #1374on Jul 11, 2016
  9. abawany commented on Nov 19, 2016

    @abawany
    abawany
    on Nov 19, 2016
    More actions

    BTW, this also happens with Node Error type (https://nodejs.org/api/errors.html). I have worked around it by logging err.stack but this is highly inconvenient. I wish the logger did not force me to watch out for its specific quirks - I use the project winston-googlecloud and it is extremely inconvenient to have to work around the gcloud limitation in my code whereas winston is able to log errors sanely.

  10. stephenplusplus commented on Nov 19, 2016

    @stephenplusplus
    stephenplusplus
    on Nov 19, 2016
    Contributor
    More actions

    Can you send a PR?

  11. abawany commented on Nov 20, 2016

    @abawany
    abawany
    on Nov 20, 2016
    More actions

    Unfortunately I don't have a PR to submit - I modified instances in my code to never invoke the log with an Error object. To add more context: I use the package winston-googlecloud to enable me to use winston for logging in my service.

  12. stephenplusplus commented on Nov 21, 2016

    @stephenplusplus
    stephenplusplus
    on Nov 21, 2016
    Contributor
    More actions

    I might be misunderstanding, but I'll try to summarize the problem:

    We let you write log entries with Error objects, but when you try to read the entries back, it's just a string.

    If that's correct, I believe that's because we are trying to be invisible with user-provided data. Unfortunately, we can't simply write the Error object to the Logging API, we have to convert it to a string. And we don't want to put it some library-specific flag like "GCN-ERROR: {error}.toString()". But without such a flag, we can't know what's an error and what's not while we're reading it back.

    A flag like "GCN-ERROR" could be used in a layer on top of ours to make logging errors more sane, i.e. winston-googlecloud. But being on the bottom layer, we have to be as transparent as possible to enable other such layers to decorate on top of us, and not tamper with the data we get from the user.

    Let me know if that's not what we're talking about, or if there's another way to solve this problem altogether from this library. We definitely want to make it as easy as possible here, working within the parameters defined above.

  13. zbjornson commented on Nov 22, 2016

    @zbjornson
    zbjornson
    on Nov 22, 2016
    ContributorAuthor
    More actions

    I haven't used Winston or winston-googlecloud, but I do use Bunyan (and help maintain bunyan-stackdriver). Bunyan has this bit that nicely JSON-ifies Errors: https://github.com/trentm/node-bunyan/blob/master/lib/bunyan.js#L1155-L1168. This seems like the right level to deal with non-JSON types (i.e. I agree there shouldn't be special handling in gcloud, because it's then much harder to override the behavior if the base API is the problem point).

  14. abawany commented on Nov 22, 2016

    @abawany
    abawany
    on Nov 22, 2016
    More actions

    True, I guess I can submit a patch to winston-googlecloud to detect instances of Error and invoke toString() in such cases. Effectively that's what I ended up doing in my service by grepping and scrubbing for such instances.

  15. JustinBeckwith
    assigned
    yoshi-automation
    on Feb 1, 2021
  16. 5 remaining items

  17. sofisl
    added 9 commits that reference this issue on Jan 27, 2026

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    1a82ba3

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    2bfad0a

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    e5d006b

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    ba636de

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    44b5c7e

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    4cce991

    feat: add support for RANGE type (#1352)

    795daf6

    Revert "feat: add support for RANGE type (#1352)" (#1358)

    1e6e182

    feat: add support for RANGE type (#1352) (#1360)

    c72084e
  18. sofisl
    added 4 commits that reference this issue on Feb 24, 2026

    fix: create new batch for writes to the same doc (#1352)

    0baecbb

    chore: release 5.6.0 (#1352)

    ca87d57

    build: add generated-files bot config (#1352)

    91e658a

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    1e44a97
  19. GautamSharda
    added a commit that references this issue on Mar 5, 2026

    Revert "fix: clarify the gax-nodejs usage in README (#1352)" (#1409) (#…

    85bfc34
  20. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    chore: release 5.6.0 (googleapis#1352)

    af5b148
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @yoshi-automation
    yoshi-automation

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

    You are visitor 01402792 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.