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

logging: Serialization of Native Types #1352

Closed
zbjornson opened this issue Jun 1, 2016 · 11 comments
Closed

logging: Serialization of Native Types #1352

zbjornson opened this issue Jun 1, 2016 · 11 comments
Assignees
Labels
api: logging Issues related to the Cloud Logging API.

Comments

@zbjornson
Copy link
Contributor

zbjornson commented Jun 1, 2016

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.

@stephenplusplus
Copy link
Contributor

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?

@stephenplusplus stephenplusplus added the api: logging Issues related to the Cloud Logging API. label Jun 2, 2016
@stephenplusplus stephenplusplus changed the title logging: Serialization of Date, Error logging: Serialization of Native Types Jun 2, 2016
@zbjornson
Copy link
Contributor Author

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.

@stephenplusplus
Copy link
Contributor

@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?

@filipjs
Copy link

filipjs commented Jun 8, 2016

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.

@zbjornson
Copy link
Contributor Author

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.

@abawany
Copy link

abawany commented Nov 19, 2016

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.

@stephenplusplus
Copy link
Contributor

Can you send a PR?

@abawany
Copy link

abawany commented Nov 20, 2016

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.

@stephenplusplus
Copy link
Contributor

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.

@zbjornson
Copy link
Contributor Author

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).

@abawany
Copy link

abawany commented Nov 22, 2016

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.

sofisl pushed a commit that referenced this issue Nov 11, 2022
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>
Source-Link: googleapis/synthtool@e1557e4
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:c2641f0628c1077d504eca6b065517b0cc54336f09a9a38e3614c4b412dd9d37
sofisl pushed a commit that referenced this issue Nov 11, 2022
…530)

This reverts commit e1557e468fd986c952ba718d9ff90e1d87390209.
Source-Link: googleapis/synthtool@8a475dc
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:ba0957cb15a1b8ca7ec2795c7783cd09cb68be2de9f4a7c69aa15b759c622735

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this issue Nov 11, 2022
…21)

This reverts commit e1557e468fd986c952ba718d9ff90e1d87390209.
Source-Link: googleapis/synthtool@8a475dc
Post-Processor: gcr.io/repo-automation-bots/owlbot-nodejs:latest@sha256:ba0957cb15a1b8ca7ec2795c7783cd09cb68be2de9f4a7c69aa15b759c622735
sofisl pushed a commit that referenced this issue Nov 12, 2022
…30)

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

This reverts commit e1557e468fd986c952ba718d9ff90e1d87390209.
Source-Link: googleapis/synthtool@8a475dc
Post-Processor: gcr.io/repo-automation-bots/owlbot-nodejs:latest@sha256:ba0957cb15a1b8ca7ec2795c7783cd09cb68be2de9f4a7c69aa15b759c622735

* owlbot-nodes is in cloud-devrel-public-resources

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Jeffrey Rennie <rennie@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API.
Projects
None yet
Development

No branches or pull requests

5 participants