steeltoe serilog dynamic logger not working after migrating to steeltoe 3.0 - vmware

I was using steeltoe 2.4.3 in my .net core 3.1 application. Recently I updated steeltoe packages to v3.0.1 and it looks like logs are not coming in serilog format. I am not able to figure out what is wrong. I do have the serilog configuration in my appsettings like below.
{
"management": {
"endpoints": {
"path": "/myexample/cloudfoundryapplication",
"cloudfoundry": {
"validateCertificates": false
},
"actuator": {
"exposure": {
"include": [ "*" ],
"exclude": [ "env", "refresh" ]
}
}
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Information",
"Steeltoe": "Information"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
},
{
"Name": "Trace",
"Args": {
"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}
],
"Enrich": [ "FromLogContext" ]
},
"AllowedHosts": "*"
}
Program.cs is like below
public static class Program
{
public static void Main(string[] args)
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.AddCloudFoundryConfiguration()
.ConfigureLogging((builderContext, loggingBuilder) =>
{
// Add Serilog Dynamic Logger
loggingBuilder.AddDynamicSerilog();
})
.AddCloudFoundryActuators()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
My .csproj looks iike below.
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Update="wwwroot\**\*;*.yml">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Serilog.Sinks.Trace" Version="2.1.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
<PackageReference Include="Steeltoe.Extensions.Logging.DynamicSerilogCore" Version="3.0.1" />
<PackageReference Include="Steeltoe.Management.CloudFoundryCore" Version="3.0.1" />
<PackageReference Include="Steeltoe.Extensions.Configuration.CloudFoundryCore" Version="3.0.1" />
</ItemGroup>
</Project>

AddDynamicSerilog doesn't (currently) add a console sink, try updating your code to look like this:
AddDynamicSerilog(new LoggerConfiguration().WriteTo.Console())
This PR will result in the Console sink being added automatically if no configuration is provided, and it will probably ship in Steeltoe 3.0.2 (no ETA yet)

Related

Angular v12 - Unit Test - [ERROR] No specs found

After developing my Angular application I would like to run unit tests with Karma and Jasmine.
I haven't written any unit-tests yet, but trying to run the default ones, with the 'ng test' command, I notice that the .spec files are not recognized by Karma-Jasmine.
Inside the browser, Karma gives the following message: "Incomplete, no specs found", in the terminal "Executed 0 of 0 SUCCESS".
I tried to generate a new application with the Angular CLI and to run the unit test. And it works.
Within my application, the Karma configuration files have not been touched, they are the same as those of the test application, and I don't understand why the .spec files are not recognized.
angular.json
{
"$schema": "./node_modules/#angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"dibfibo": {
"projectType": "application",
"schematics": {
"#schematics/angular:component": {
"style": "scss"
},
"#schematics/angular:application": {
"strict": true
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/dibfibo",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
},
"configurations": {
"production": {
"budgets": [
{
"type": "initial",
"maximumWarning": "500kb",
"maximumError": "1mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "2kb",
"maximumError": "4kb"
}
],
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "#angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "dibfibo:build:production"
},
"development": {
"browserTarget": "dibfibo:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "#angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "dibfibo:build"
}
},
"test": {
"builder": "#angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"inlineStyleLanguage": "scss",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.scss"
],
"scripts": []
}
}
}
}
},
"defaultProject": "dibfibo"
}
karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '#angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage'),
require('#angular-devkit/build-angular/plugins/karma')
],
client: {
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
jasmineHtmlReporter: {
suppressAll: true // removes the duplicated traces
},
coverageReporter: {
dir: require('path').join(__dirname, './coverage/dibfibo'),
subdir: '.',
reporters: [
{ type: 'html' },
{ type: 'text-summary' }
]
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
restartOnFileChange: true
});
};

Running Unit Test with Intern 4

We migrate our intern 3 test to intern 4.
Unfortunately I get following error for my unit tests (functional tests works)
Error: scriptError
No stack or location
Error: Dojo loader error:scriptError
No stack or location
My test:
File located:
build/webapp/app/tests/unit/test.js
define([], function () {
const {registerSuite} = intern.getInterface("object");
let assert = intern.getPlugin("chai").assert;
registerSuite("Test", function () {
return {
beforeEach() {
console.log("test");
},
tests: {
defaults() {
console.log("test3");
console.log("test2");
},
toggle() {
console.log("test4");
console.log("test5");
console.log("test8");
console.log("test9");
}
}
};
});
});
My intern.json (see below)
{
"loader": {
"script": "dojo",
"options": {
"packages": [
{
"name": "app",
"location": "build/webapp/app"
},
{
"name": "dojo",
"location": "lib/dojo"
},
{
"name": "dojox",
"location": "lib/dojox"
},
{
"name": "dijit",
"location": "lib/dijit"
},
{
"name": "dstore",
"location": "lib/dstore"
}
]
}
},
"suites": [
"./build/webapp/app/tests/unit/test.js"
],
"functionalSuites": [
"./build/webapp/app/tests/functional/TestDocumentation.js"
],
"functionalTimeouts": {
"connectTimeout": 60000
},
"defaultTimeout": 180000,
"filterErrorStack": true,
"tunnel": "selenium",
"tunnelOptions": {
"version": "3.8.0",
"drivers": [
{
"name": "ie",
"arch": "Win64",
"version": "3.8.0"
}
]
},
"debug": true,
"environments": [
"node",
{
"browserName": "internet explorer",
"fixSessionCapabilities": "no-detect"
}
]
}
If I execute the unit test in the node envrioment it works fine but after launching to the ie my test failed with the Dojo loader error.
Dojo & intern are aviable in the node_moudles directory.
Best Regards
Kai
Add the lines below to the json file solved my problem
{
"name": "tests",
"location": "build/webapp/app/tests/"
}

A module in aws cognito is missing: errorMessage": "Cannot find module './lib/browser_loader

I am trying to use cognito for my project but when I follow all the necessary set up explained I am not able to run it and in my lamda test console I get the following error:
{
"errorMessage": "Cannot find module './lib/browser_loader'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:417:25)",
"Module.require (module.js:497:17)",
"require (internal/module.js:20:19)",
"Object.<anonymous> (/var/task/index.js:3651:1)",
"__webpack_require__ (/var/task/index.js:20:30)",
"webpackUniversalModuleDefinition (/var/task/index.js:149:28)",
"Object.<anonymous> (/var/task/index.js:156:3)",
"__webpack_require__ (/var/task/index.js:20:30)",
"Object.<anonymous> (/var/task/index.js:75:18)"
]
}
I follow the instruction mentioned in the following link:https://github.com/aws/amazon-cognito-identity-js
So I use webpack and json loader to first transform the code. here is my webpack code:
{
"name": "bnitjouathprovider",
"version": "0.0.1",
"description": "provide the server for password management using cognito",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack"
},
"author": "Hamed Minaee",
"license": "ISC",
"devDependencies": {
"amazon-cognito-identity-js": "^1.18.0",
"aws-sdk": "git://github.com/chrisradek/aws-sdk-js.git#webpack",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"brfs": "^1.4.3",
"json-loader": "^0.5.4",
"transform-loader": "^0.2.4",
"webpack": "^3.0.0-rc.1"
},
"dependencies": {
"amazon-cognito-identity-js": "^1.18.0"
},
"babel": {
"presets": [
"es2015",
"stage-0"
]
}
}
Here is my webpack.config:
var path = require("path");
var DIST_DIR = path.resolve(__dirname, "dist");
module.exports = {
// Example setup for your project:
// The entry module that requires or imports the rest of your project.
// Must start with `./`!
entry: './',
// Place output files in `./dist/my-app.js`
output: {
path: DIST_DIR,
filename: 'index.js'
},
module: {
noParse: [
/aws\-sdk/,
],
loaders: [
{
test: /\.json$/,
loader: 'json'
}
]
}
};
So now I assume my code should be ready to transform. here is my code:
var AWSCognito = require('amazon-cognito-identity-js/dist/amazon-cognito-
identity');
exports.handler = function (event, context, callback) {
registerUset();
callback(null, "some success message");
}
var registerUset = function () {
}
As you see it is just a simple java script code with nothing in it. Now when I do : npm run build I see the compiled js file and I do not get any error.
However when I zip the js and node module folder and upload and test it in lambda console I get the following error:
"errorMessage": "Cannot find module './lib/browser_loader'"
The full stack is posted at the beginning of the post. To me it does not make sense. Is it an aws bug or am I missing sth?
I found the solution to my problem in case if anyone faces the same issue:
Thanks to:
http://www.rricard.me/es6/aws/lambda/nodejs/2015/11/29/es6-on-aws-lambda.html
So basically I need to use both babel and json as loaders so the key part for solving the solution was :
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['es2015'],
plugins: ['syntax-flow', 'transform-flow-strip-types']
}
},
{
test: /\.json$/,
loader: 'json'
}
]
}

Boost library with node.js addon - segfault

package.json:
{
"name": "BoostRegexJS",
"version": "0.0.1",
"description": "Boost::Regex API for node.js",
"main": "regex.js",
"private": true,
"dependencies": {
"bindings": "~1.2.1",
"nan": "^2.0.0"
},
"scripts": {
"test": "node regex.js"
},
"gypfile": true
}
bindings.gyp
{
"targets": [
{
"target_name": "boostregex",
"sources": [ "regex.cpp" ],
"include_dirs": [
"~/boost/include",
"<!(node -e \"require('nan')\")"
],
"libraries": [
"~/boost/lib/libboost_regex.so"
],
"cflags_cc!": [ "-fno-rtti", "-fno-exceptions" ],
"cflags!": [ "-fno-exceptions" ],
"conditions": [
['OS=="mac"', {
"xcode_settings": {
'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++', '-v'],
'OTHER_LDFLAGS': ['-stdlib=libc++'],
'MACOSX_DEPLOYMENT_TARGET': '10.7',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
}
}],
['OS!="win"', {
'include_dirs': [ 'config/win' ],
'cflags+': [ '-std=c++11' ],
'cflags_c+': [ '-std=c++11' ],
'cflags_cc+': [ '-std=c++11' ],
}]
]
}
]
}
regex.cpp
#include <nan.h>
#include <string>
#include <boost/regex.hpp>
void Method(const Nan::FunctionCallbackInfo<v8::Value>& info) {
info.GetReturnValue().Set(Nan::New("worldd").ToLocalChecked());
}
void Init(v8::Local<v8::Object> exports) {
exports->Set(Nan::New("hello").ToLocalChecked(), Nan::New<v8::FunctionTemplate>(Method)->GetFunction());
}
NODE_MODULE(boostregex, Init)
Just because #include<boost/regex.hpp> I've got segfault when run this code:
var addon = require('bindings')('boostregex');
console.log(addon.hello()); // 'world'
without this include, addon works fine..
weird because it is just header file..
The Boost libraries compiled succesfully (tried clang and gcc, both ok)
FreeBSD, Node.js v4
Anyidea why segfault?

Loopback mixins not working?

I'm trying to use mixins in Loopback, but it seems I'm making some stupid mistake.
I defined the following mixin in "common/mixins/test.js"
module.exports = function(Model, message) {
console.log(message);
};
In the "user.json" file I put the following:
{
"name": "user",
... ,
"mixins":{
"test":"hello world"
}
}
I did not change the meta property in the "model-config.json" file , it is
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins"
]
},
... ,
"user": {
"dataSource": "mysql",
"public": true,
"options": {
"emailVerificationRequired": true
}
},
...
}
I expect to see "Hello world" when I start the server, but nothing is logged, what am I doing wrong?
The mixin options should be an object.
Try this please :
"mixins":{
"Test":{"message": "hello world"}
}
module.exports = function(Model, options) {
console.log(options.message);
};