TelemetryProcessor not called without an InstrumentationKey? - azure-application-insights

I've created a class derived from ITelemetryProcessor, so I can capture telemetry data during a unit test of a C# .Net Class Library. Being a unit test, there is no InstrumentationKey provided as unit tests should have no network dependencies. (I cannot factor the telemetry to an injected interface.)
I create and use TelemetryClient's and log custom events during the unit test methods. However, I noticed my Process() method was not getting called when I logged telemetry items.
After doing some experimentation, I realized that if set an InstrumentationKey to a dummy Guid, then my Processor() method started to get called.
TelemetryConfiguration.Active.InstrumentationKey = Guid.NewGuid().ToString();
Question: why should I need to provide an InstrumentationKey in order for processors to be invoked?
Thanks
-John

TelemetryProcessor's are meant to apply additional processing/filtering to telemetry items before being sent to AI. If there is no ikey, then there is no point sending to AI as it will not be accepted anyway. Why run overhead of running all processors.

Related

symfony 5 how to mock/replace service in container

I want to make a mock for some class in my functional test. Let's say I want to mock some custom command bus realization.
First of all I need to register that service as a public in the services_test.yaml:
services:
_defaults:
public: true
App\CommandBus: ~
but still even if I did so I'm getting error service is already initialized, you cannot replace it when doing something like:
$commandBus = $this->createMock(CommandBus::class);
$commandBus->expects(self::once())
->method('dispatch')
->with($data)
->willReturn($response);
self::$container->set(CommandBus::class, $commandBus);
So how can I easily mock some object and insert mocked version to the container???
Probably I can make some wrapper for tests link it with interface in services_test.yaml, and add a methods like setExpectiotion which will chekc if expectation set and if so instead of running command return it. But it's extra work and it's taking a lot of time to design such a class for each service I want to mock.
Is there any other way to mock some service?? Thanks in advice!
I assume your command bus is using an asynchronous transport type. If you wish you can solve this problem using sync transport for tests instead. You don't need to mock it in this case, because if you will mock command bus, you will test mock instead of the whole process.
Let's create a new config in config/packages/test/messenger.yaml
framework:
messenger:
transports:
command_bus: 'sync://'
Then enable the functional test without worrying about the consumer.
If you want to debug container for tests, you can check it using command
./bin/console debug:container -e test
Please let me know if that solves your problem.

Enqueue controller action process

Symfony 2.8
Using https://github.com/j-guyon/CommandSchedulerBundle to manage periodic Command executions.
Each of these Command executions invokes an specific Service based on the Command arguments.
Being in the Services (all of them implementing the same Interface and extending an Abstract class), the plan is to create and execute sub-processes (asynchronously if possible)
Based in your experience, which will be the best way to deal with that sub-processes?
Create a Process object (based on a Controller Action) for each sub-process, and run them synchronously (https://symfony.com/doc/2.8/components/process.html)
Use kind of Queue Bundle to deal with all of them (Process or Messages or whatever), such https://php-enqueue.github.io/symfony or https://github.com/armetiz/LeezyPheanstalkBundle (any other suggestion?)
Cheers!

a service which would be able to run jobs on a timed basis

I am working for my client using Asp.net webAPI2 and angularJS. Now my client have following requirement,but i am unable to understand what type of project i have to create like WebAPI project,window service or any other? Anyone please tell me what the client actually want and how can i do it?
QueueManager will need to be some kind of a service which would be able to run jobs on a timed basis. We envision it being a service that runs on a continuous loop, but has a Thread.Sleep at the end of each iteration with a duration of x-seconds (“x” being set in a config file.) You should create this QueueManager service as a new project within the Core.Jobs project; I would like to have the project name be “Core.Jobs.QueueManager”, along with the base namespace.
Here are the functions that the QueueManager will do for each iteration:
1) Do a worker healthcheck (JobsAPI: Queue/WorkerHealthCheck – already created)
a. This method will just return a 200 status code, and a count of workers. Not need to act on the return value.
Look at Hangfire, it is quite easy to set up and simple to use.
http://docs.hangfire.io/en/latest/background-methods/performing-recurrent-tasks.html

How to get the user who initiated the process in IBM BPM 8.5?

How to get the user who initiated the process in IBM BPM 8.5. I want to reassign my task to the user who actually initiated the process. How it can be achieved in IBM BPM?
There are several ways to get that who initiated a Task , But who initiated a process Instance is somewhat different.
You can perform one out of the following :
Add a private variable and assign it tw.system.user_loginName at the POST of start. you can access that variable for user who initiated the process.(It will be null or undefined for the scenario if task is initiated by some REST API or UCA.)
Place a Tracking group after Start event . Add a input variable to it as username , assign it a value same as tw.system.user_loginName. So whenever Process is started entry will be inserted to DB Table.You can retrieve this value from that view in PerformanceDB.
Also there might be some table ,logging the process Instances details , where you can find the user_id directly.
I suggest you to look in getStarter() method of ProcessInstanceData API.
Official Documentation on API
This link on IBM Developerworks should help you too: Process Starter
Unfortunately there's not an Out Of The Box way to do this - nothing is recorded in the Process Instance that indicates "who" started a process. I presume this is because there are many ways to launch a process instance - from the Portal, via a Message Event, from an API call, etc.
Perhaps the best way to handle this is to add a required Input parameter to your BPD, and supply "who" started the process when you launch it. Unfortunately you can't supply any inputs from the OOTB Portal "New", but you can easilty build your own "launcher".
If you want to route the first task in process to the user that started the process the easiest approach is to simply put the start point in the lane, and on the activity select routing to "Last User In Lane". This will take care of the use case for you without requiring that you do the book keeping to track the user.
Its been a while since I've implemented this, so I can't remember if it will work elegantly if you have system steps before the first task, but this can easily be handled by moving the system steps into the human service to be executed as part of that call, rather than as a separate step in the BPD.
Define variable as string type and using script task to define the login user that use this task and assign it to your defined variable to keep to you in all of the process as initiator of the task.
You can use this line of code to achieve the same:
tw.system.user_loginName

Are group subscriptions automatically handled on Reconnect?

I have a chat room using SignalR Hub for its messaging. Occasionally I get reports from users where it 'freezes'. Now this can be interpreted as no messages are coming through, I suspect as they have been dropped from a group.
My question is, does the connection get re-subscribed back into its groups automatically, or do you have to do something yourself in the Reconnect method:
public Task Reconnect(IEnumerable<string> groups)
{
return Clients.rejoined(Context.ConnectionId, DateTime.Now.ToString());
}
Yes, in 1.0.0.0-alpha1 you can enable auto rejoining of groups by using the new AutoRejoiningGroupsModule pipeline module using the EnableAutoRejoiningGroups extension method for the hub pipeline you build. This feature was not available in previous versions of the framework.
So you would end up with this somewhere in your startup code:
GlobalHost.HubPipeline.EnableAutoRejoiningGroups();
UPDATE:
Please note that the final version of SignalR 1.0 made auto-rejoining of groups the default behavior and so EnableAutoRejoiningGroups was removed. You can see this answer for more details.

Resources