@@ -2,13 +2,15 @@ import * as R from 'ramda';
22import fetch from 'node-fetch' ;
33import FormData from 'form-data' ;
44import webpack from 'webpack' ;
5+ import webpackLog , { Level } from 'webpack-log' ;
56
67export interface Config {
78 serviceName : string ;
89 serviceVersion : string ;
910 publicPath : string ;
1011 serverURL : string ;
1112 secret ?: string ;
13+ logLevel ?: Level ;
1214}
1315
1416export default class ElasticAPMSourceMapPlugin implements webpack . Plugin {
@@ -18,11 +20,24 @@ export default class ElasticAPMSourceMapPlugin implements webpack.Plugin {
1820 }
1921
2022 apply ( compiler : webpack . Compiler ) : void {
23+ const logger = webpackLog ( {
24+ name : 'ElasticAPMSourceMapPlugin' ,
25+ level : this . config . logLevel || 'warn'
26+ } ) ;
27+
2128 compiler . hooks . afterEmit . tapPromise ( 'ElasticAPMSourceMapPlugin' , compilation => {
29+ logger . debug ( `starting uploading sourcemaps with configs: ${ JSON . stringify ( this . config ) } .` ) ;
30+
2231 const { chunks } = compilation . getStats ( ) . toJson ( ) ;
2332
2433 return R . compose (
25- ( promises : Array < Promise < void > > ) => Promise . all ( promises ) ,
34+ ( promises : Array < Promise < void > > ) =>
35+ Promise . all ( promises )
36+ . then ( ( ) => logger . debug ( 'finished uploading sourcemaps.' ) )
37+ . catch ( err => {
38+ logger . error ( err ) ;
39+ throw err ;
40+ } ) ,
2641 R . map ( ( { sourceFile, sourceMap } ) => {
2742 const formData = new FormData ( ) ;
2843 formData . append ( 'sourcemap' , compilation . assets [ sourceMap ] . source ( ) ) ;
@@ -42,11 +57,13 @@ export default class ElasticAPMSourceMapPlugin implements webpack.Plugin {
4257 . then ( response => {
4358 if ( response . ok ) return response . json ( ) ;
4459 else {
45- throw new Error ( `Error while uploading ${ sourceMap } to Elastic APM` ) ;
60+ const errMessage = `Error while uploading ${ sourceMap } to Elastic APM` ;
61+ logger . error ( errMessage ) ;
62+ throw new Error ( errMessage ) ;
4663 }
4764 } )
4865 . then ( ( ) => {
49- console . info ( `Uploaded ${ sourceMap } to Elastic APM`) ; // eslint-disable-line no-console
66+ logger . debug ( `uploaded ${ sourceMap } to Elastic APM. `) ;
5067 } ) ;
5168 } ) ,
5269 R . map ( ( { files } ) => {
0 commit comments