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

Log out a detailed error msg while inserting data into big query #229

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gcp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@walmartlabs/cookie-cutter-gcp",
"version": "1.4.0-beta.2",
"version": "1.4.0-beta.3",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 12 additions & 0 deletions packages/gcp/src/BigQueryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
IMetrics,
IRequireInitialization,
OpenTracingTagKeys,
ILogger,
NullLogger,
} from "@walmartlabs/cookie-cutter-core";
import { Span, SpanContext, Tags, Tracer } from "opentracing";
import { IBigQueryClient, IBigQueryConfiguration } from ".";
Expand All @@ -36,6 +38,7 @@ export class BigQueryClient implements IBigQueryClient, IRequireInitialization {
private tracer: Tracer;
private metrics: IMetrics;
private spanOperationName: string = "BigQuery Client Call";
private logger: ILogger;

constructor(private readonly config: IBigQueryConfiguration) {
const key = this.config.privateKey.split("\\n").join("\n");
Expand All @@ -47,11 +50,13 @@ export class BigQueryClient implements IBigQueryClient, IRequireInitialization {
},
}).dataset(this.config.datasetId);
this.tracer = DefaultComponentContext.tracer;
this.logger = new NullLogger();
plameniv marked this conversation as resolved.
Show resolved Hide resolved
}

public async initialize(context: IComponentContext): Promise<void> {
this.tracer = context.tracer;
this.metrics = context.metrics;
this.logger = context.logger;
}

private spanLogAndSetTags(span: Span, funcName: string, dataset: string, table: string): void {
Expand Down Expand Up @@ -83,6 +88,13 @@ export class BigQueryClient implements IBigQueryClient, IRequireInitialization {
result: BigQueryMetricResults.Error,
error: e instanceof Error ? e.message : "",
});
let detailedErrorMsg = "";
if (e.errors) {
detailedErrorMsg = JSON.stringify(e.errors);
}
plameniv marked this conversation as resolved.
Show resolved Hide resolved
this.logger.error("An error occured while inserting data into big query", {
errorMsg: detailedErrorMsg,
});
throw e;
} finally {
span.finish();
Expand Down